/* ============================================================
   Department listing — โทนเทา-ทอง ตาม dept/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;
}

/* ---------- ตัวโหลดหน้า ---------- */
.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-band {
    width: 100%;
    background:
        radial-gradient(120% 180% at 0% 0%, rgba(232, 198, 90, .18), transparent 55%),
        linear-gradient(180deg, #2a2d33 0%, #1a1c20 100%);
    padding: clamp(2.25rem, 5vw, 3.5rem) 0 2.5rem;
}

/* โหมดภาพพื้นหลัง — วางไฟล์ที่ img/department_banner.jpg */
.page-header-band--photo {
    position: relative;
    min-height: clamp(11rem, 26vw, 18rem);
    display: flex;
    align-items: flex-end;
    padding: clamp(2.5rem, 6vw, 4rem) 0 2.75rem;
    background-color: #1a1c20;
    background-image:
        linear-gradient(
            105deg,
            rgba(26, 28, 32, .88) 0%,
            rgba(26, 28, 32, .62) 42%,
            rgba(26, 28, 32, .28) 100%
        ),
        var(--header-photo);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.page-header-band-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 15px;
    position: relative;
    z-index: 1;
}

.page-header-band .eyebrow {
    color: var(--gold-line);
    margin-bottom: .65rem;
}

.page-header-band h1 {
    font-family: 'db_helvethaica_x65_med', var(--sans);
    font-size: clamp(2rem, 4vw, 2.75rem);
    font-weight: 700;
    color: #fff;
    margin: 0 0 .55rem;
    line-height: 1.25;
    letter-spacing: .01em;
}

.page-header-band .lead {
    margin: 0;
    max-width: 36rem;
    color: rgba(247, 245, 240, .78);
    font-size: 1.02rem;
}

.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: 1120px;
    padding-top: 2rem;
    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);
}

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

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

.degree-tab {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.02rem;
    color: var(--ink-2);
    padding: .55rem 1.15rem;
    margin: 0 .4rem .75rem 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    text-decoration: none;
    transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}

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

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

.degree-tab i { color: var(--gold); font-size: .95rem; }

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

.section-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 1.5rem 1.35rem 1.75rem;
}

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

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

.section-card-title {
    font-family: 'db_helvethaica_x65_med', var(--sans);
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    line-height: 1.35;
}

.section-card-sub {
    margin: .15rem 0 0;
    font-size: .88rem;
    color: var(--muted);
}

/* ---------- การ์ดภาควิชา ---------- */
.dept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.15rem;
}

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

.dept-card:hover,
.dept-card:focus {
    transform: translateY(-3px);
    border-color: var(--gold-line);
    box-shadow: var(--lift);
    text-decoration: none;
    color: inherit;
    outline: none;
}

.dept-card-media {
    position: relative;
    display: block;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: #edeae4;
}

.dept-card-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    /* ใช้การย่อภาพคุณภาพสูงของเบราว์เซอร์ — อย่า scale ด้วย transform */
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
    -ms-interpolation-mode: bicubic;
    backface-visibility: hidden;
}

/* แถบล่าง ~10% — ภาพเดิม + filter blur เป็นพื้นข้อความ */
.dept-card-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 10%;
    min-height: 2rem;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
    /* ช่วยให้เบลอชัดขึ้นบนเบราว์เซอร์ที่รองรับ */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.dept-card-bar-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    /* สูงเท่ากรอบภาพทั้งใบเทียบกับแถบ 10% */
    height: 1000%;
    object-fit: cover;
    object-position: center;
    filter: blur(18px) brightness(.68) saturate(1.08);
    transform: scale(1.35);
    transform-origin: center bottom;
    display: block;
}

.dept-card-bar--solid {
    background: rgba(26, 28, 32, .55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* ชื่อมุมขวาล่าง บนแถบเบลอ */
.dept-card-name {
    position: absolute;
    right: .7rem;
    bottom: 0;
    z-index: 2;
    max-width: calc(100% - 1.2rem);
    height: 10%;
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans Thai', var(--sans);
    font-size: clamp(.78rem, 2.1vw, .95rem);
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    text-align: right;
    text-shadow:
        0 1px 2px rgba(0, 0, 0, .95),
        0 0 8px rgba(0, 0, 0, .75),
        1px 1px 0 rgba(0, 0, 0, .55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.dept-card-media--empty {
    background: linear-gradient(145deg, #3a3d44 0%, #1a1c20 70%);
}

.dept-empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--muted);
}

.dept-empty i {
    display: block;
    font-size: 2rem;
    color: #cfcbc2;
    margin-bottom: .75rem;
}

/* ---------- แถบข้าง ---------- */
.aside-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.aside-card .eyebrow {
    margin-bottom: .75rem;
}

.aside-select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--sans);
    font-size: .92rem;
    padding: .65rem .75rem;
    line-height: 1.4;
}

.aside-select:focus {
    outline: 2px solid var(--gold-bright);
    outline-offset: 2px;
    border-color: var(--gold-line);
}

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

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

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

.aside-action-name {
    display: block;
    font-weight: 600;
    font-size: .98rem;
    line-height: 1.35;
}

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

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

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

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

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

a:focus-visible,
button:focus-visible,
select:focus-visible {
    outline: 2px solid var(--gold-bright);
    outline-offset: 3px;
}

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

    .aside-stack {
        order: -1;
    }
}

@media (max-width: 575.98px) {
    .dept-grid {
        grid-template-columns: 1fr;
    }

    .section-card {
        padding: 1.25rem 1.1rem 1.4rem;
    }

    .section-card-title { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
    .page-header-rule::after {
        animation: none;
        display: none;
    }

    .dept-card,
    .aside-action {
        transition: none;
    }

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

@media print {
    .page-header-band,
    .degree-bar,
    .aside-stack {
        display: none !important;
    }

    .dept-list-layout {
        grid-template-columns: 1fr;
    }
}
