/* ============================================================
   Major Detail v3 — โทนเทา-ทอง ตามสีประจำมหาวิทยาลัยบูรพา
   ไฟล์นี้ทำงานแทน major-detail.css ทั้งหมด (v3 ไม่โหลดไฟล์เดิม)
   ============================================================ */

:root {
    --ink: #1a1c20;
    --ink-2: #3d424c;
    --muted: #767b86;
    /* เหลืองประจำคณะ (Y:100) ลดความอิ่มสีลงให้ไม่แย่งสายตาจากเนื้อหา
       ใช้เติมพื้นเท่านั้น คู่กับตัวอักษรสี --ink (คอนทราสต์ราว 10:1)
       ห้ามใช้เป็นสีตัวอักษรหรือเส้นบางบนพื้นขาว */
    --y-brand: #e8c65a;
    --y-brand-hover: #dcb646;
    /* เหลืองที่กดความสว่างลง สำหรับตัวอักษรและไอคอนบนพื้นขาว คอนทราสต์ราว 4.7:1 */
    --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;
}

/* ---------- ตัวโหลดหน้า ---------- */
.page-loader {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .9rem;
    background: rgba(247, 245, 240, .92);
    backdrop-filter: blur(2px);
    transition: opacity .35s ease, visibility .35s ease;
}

.page-loader.is-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--gold-line);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: page-loader-spin .75s linear infinite;
}

.page-loader-text {
    margin: 0;
    font-family: var(--sans);
    font-size: .92rem;
    font-weight: 500;
    color: var(--muted);
}

@keyframes page-loader-spin {
    to { transform: rotate(360deg); }
}

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

/* ---------- ภาพส่วนหัว ----------
   เต็มความกว้างจอ ย่อสูงตามอัตราส่วนเมื่อหน้าจอแคบลง */
.page-header {
    margin-bottom: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    background-color: var(--header-band, #ffffff);
}

.page-header-frame {
    overflow: hidden;
    background: transparent;
}

.page-header img,
#headerImage {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    object-position: center;
}

/* เส้นคั่นใต้ส่วนหัว — ไล่ทอง→ครีม + แสงสะท้อนเลื่อนซ้าย→ขวา */
.page-header-rule {
    position: relative;
    width: 100%;
    height: 3px;
    overflow: hidden;
    background: linear-gradient(
        90deg,
        #8f6f22 0%,
        #c39429 18%,
        #e8c65a 38%,
        #f3e2a8 55%,
        #f7f0d4 72%,
        #f5f6f8 100%
    );
}

.page-header-rule::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 252, 235, 0) 35%,
        rgba(255, 255, 255, .85) 50%,
        rgba(255, 252, 235, 0) 65%,
        transparent 100%
    );
    transform: translateX(-120%);
    animation: header-rule-sheen 3.6s ease-in-out infinite;
}

@keyframes header-rule-sheen {
    0%, 18% { transform: translateX(-120%); opacity: 0; }
    28% { opacity: 1; }
    58% { transform: translateX(120%); opacity: .9; }
    70%, 100% { transform: translateX(120%); opacity: 0; }
}

/* ---------- โครงหน้า ---------- */
.page-container {
    max-width: 980px;
    padding-top: 2.25rem;
    padding-bottom: 4.5rem;
}

/* ---------- ตัวอักษรร่วม ---------- */
.eyebrow {
    font-family: var(--sans);
    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);
}

/* ---------- ตัวเลือกฉบับปรับปรุง ---------- */
.edition-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem 1.25rem;
    margin-bottom: 2.25rem;
}

.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);
}

.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);
}

.edition-flag {
    font-family: var(--sans);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--gold);
    background: var(--gold-tint);
    border: 1px solid var(--gold-line);
    border-radius: 999px;
    padding: .1rem .5rem;
    white-space: nowrap;
}

.edition-single {
    display: flex;
    align-items: baseline;
    gap: .75rem;
    font-size: 1.08rem;
    color: var(--ink);
    margin-bottom: 2.25rem;
}

.edition-single .eyebrow { margin-bottom: 0; }

/* ---------- แผงข้อมูลสรุป ---------- */
.spec-sheet {
    background: var(--paper);
    border: 1px solid var(--line);
    border-top: 3px solid var(--y-brand);
    border-radius: var(--r-lg);
    padding: 1.75rem 2rem 2rem;
    margin-bottom: 1.5rem;
}

.spec-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
    margin: 0;
}

/* ชื่อปริญญาเป็นข้อความยาวที่สุดในกล่อง ให้กินเต็มแถวจะได้ไม่ตัดคำแปลก ๆ */
.spec-row-wide { grid-column: 1 / -1; }

.spec-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: .85rem;
    padding: .9rem 1rem;
    background: #fbfaf7;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
}

.spec-icon {
    grid-row: span 2;
    width: 36px;
    height: 36px;
    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: .9rem;
}

.spec-row dt {
    grid-column: 2;
    align-self: end;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .1em;
    color: var(--muted);
    margin-bottom: .25rem;
}

.spec-row dd {
    grid-column: 2;
    align-self: start;
    font-size: 1.08rem;
    color: var(--ink);
    line-height: 1.6;
    margin: 0;
}

/* ---------- ส่วนเนื้อหา ---------- */
.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;
    /* เผื่อ navbar ที่ fixed อยู่ด้านบนทุกหน้า (56px) */
    scroll-margin-top: 5rem;
}

.doc-section-accent {
    background: var(--gold-tint);
    border-color: var(--gold-line);
}

.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-accent .doc-section-head {
    border-bottom-color: var(--gold-line);
}

.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-accent .doc-section-icon {
    background: var(--paper);
}

.doc-section-title {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 1.55rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    line-height: 1.4;
    letter-spacing: 0;
}

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

/* ---------- เนื้อหา HTML จากระบบหลังบ้าน ---------- */
.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;
}

/* ---------- คณาจารย์ ---------- */
.chair {
    display: flex;
    align-items: center;
    gap: 1.75rem;
    padding-bottom: 1.75rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1.75rem;
}

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

.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 {
    flex: 0 0 auto;
    width: 132px;
}

/* รูปบุคลากรดึงมาจากโดเมนภายนอก ถ้าไฟล์หายให้ขึ้นไอคอนแทนรูปแตก */
.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;
}

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

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

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

/* หัวข้อย่อยแยกกลุ่มบุคลากร */
.people-group + .people-group {
    margin-top: 2.25rem;
    padding-top: 2rem;
    border-top: 1px solid var(--line);
}

.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 {
    font-size: .76rem;
    font-weight: 500;
    color: var(--gold);
    background: var(--gold-tint);
    border: 1px solid var(--gold-line);
    border-radius: 999px;
    padding: .05rem .55rem;
}

/* ---------- แกลเลอรี ---------- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: .75rem;
}

.gallery-item {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: var(--r-md);
    background: #edeae4;
    transition: transform .25s ease, box-shadow .25s ease;
}

.gallery-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--lift);
}

.gallery-item img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    transition: transform .45s ease;
}

.gallery-item:hover img { transform: scale(1.05); }

.gallery-zoom {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    background: rgba(26, 28, 32, .42);
    opacity: 0;
    transition: opacity .25s ease;
}

.gallery-item:hover .gallery-zoom,
.gallery-item:focus .gallery-zoom { opacity: 1; }

/* ---------- แถบปุ่มเอกสาร ---------- */
.action-bar {
    display: flex;
    flex-wrap: nowrap;
    gap: .75rem;
    margin-bottom: 2rem;
    align-items: stretch;
}

.action {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex: 1 1 0;
    min-width: 0;
    padding: .75rem .9rem;
    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: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: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: .92rem;
    font-weight: 600;
    color: inherit;
    line-height: 1.35;
}

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

/* เอกสารหลักของหลักสูตร ทำให้เด่นกว่ารายการอื่น */
.action-primary {
    background: var(--y-brand);
    border-color: var(--y-brand);
    color: var(--ink);
}

.action-primary:hover {
    background: var(--y-brand-hover);
    border-color: var(--y-brand-hover);
    color: var(--ink);
}

.action-primary .action-name { font-weight: 700; }

.action-primary .action-icon {
    background: rgba(255, 255, 255, .8);
    border-color: rgba(26, 28, 32, .12);
    color: var(--gold);
}

.action-primary .action-meta { color: rgba(26, 28, 32, .74); }

.action-disabled,
.action-disabled:hover {
    background: #f3f1ec;
    border-color: #e5e1d8;
    color: #9a958c;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    box-shadow: none;
    opacity: .72;
    text-decoration: none;
}

.action-disabled.action-primary,
.action-disabled.action-primary:hover {
    background: #efece4;
    border-color: #e0dbd0;
    color: #9a958c;
}

.action-disabled .action-icon {
    background: #eceae4;
    border-color: #ddd8ce;
    color: #b0aaa0;
}

.action-disabled .action-meta { color: #a8a39a; }

.action-empty {
    font-size: .9rem;
    color: var(--muted);
    margin-bottom: 2rem;
}

/* ---------- ท้ายหน้า ---------- */
.page-note {
    margin: 2.5rem 0 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
    font-size: .9rem;
    color: var(--muted);
    text-align: center;
}

.page-note a {
    color: var(--ink-2);
    border-bottom: 1px solid var(--gold-line);
    text-decoration: none;
}

.page-note a:hover { color: var(--gold); }

/* ---------- สถานะไม่มีข้อมูล ---------- */
.empty-state {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 4rem 2rem;
    text-align: center;
    color: var(--muted);
}

.empty-state i {
    display: block;
    font-size: 2.25rem;
    color: #cfcbc2;
    margin-bottom: 1rem;
}

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

.empty-state p:last-child { margin-bottom: 0; }

/* ---------- โฟกัสที่มองเห็นได้ ---------- */
a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--gold-bright);
    outline-offset: 3px;
}

/* ---------- จอเล็ก ---------- */
@media (max-width: 767.98px) {
    .page-container {
        padding-top: 1.5rem;
        padding-bottom: 3rem;
    }

    .spec-sheet {
        padding: 1.5rem 1.25rem .5rem;
    }

    .spec-list {
        grid-template-columns: 1fr;
        column-gap: 0;
    }

    .doc-section {
        padding: 1.5rem 1.25rem 1.75rem;
    }

    .doc-section-title { font-size: 1.35rem; }

    .doc-section-head {
        gap: .75rem;
        margin-bottom: 1.25rem;
    }

    .edition-bar {
        gap: .5rem;
        align-items: flex-start;
        flex-direction: column;
    }

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

    .edition-tabs {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .edition-tabs .nav-link.edition-tab {
        padding: .6rem .9rem;
        white-space: nowrap;
    }

    .action-bar {
        flex-wrap: wrap;
    }

    .action {
        flex: 1 1 calc(50% - .4rem);
        min-width: calc(50% - .4rem);
    }

    .chair {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.25rem;
    }

    .portrait-lg { width: 116px; }

    .people-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 1.25rem 1rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: .5rem;
    }

    .action {
        flex: 1 1 100%;
    }
}

/* ---------- ลดการเคลื่อนไหว ---------- */
@media (prefers-reduced-motion: reduce) {
    .portrait img,
    .gallery-item img,
    .action,
    .action-primary {
        transition: none;
    }

    .gallery-item:hover img { transform: none; }

    .page-header-rule::after {
        animation: none;
        display: none;
    }

    .page-loader-spinner {
        animation: none;
        border-top-color: var(--gold-line);
        opacity: .7;
    }
}

/* ---------- สั่งพิมพ์ ---------- */
@media print {
    body { background: #fff; }

    .page-header,
    .edition-bar,
    .action-bar,
    .gallery-zoom {
        display: none !important;
    }

    .tab-pane {
        display: block !important;
        opacity: 1 !important;
    }

    .doc-section,
    .spec-sheet {
        border-color: #ccc;
        break-inside: avoid;
    }
}
