/* =====================================================================
   ระบบค่าสมนาคุณการผลิตหนังสือหรือตำราทางเศรษฐศาสตร์ — layout หลัก
   CSP: style-src 'self' → ห้าม inline style ในหน้า PHP; เพิ่ม utility class ที่นี่

   Design tokens (ใน :root ด้านล่าง) — ใช้ตัวแปรเสมอ ห้ามใส่สี hex ใหม่ในกฎ CSS
   หลักการใช้สี ตัวอักษร รูปทรง และ component อธิบายไว้ใน DESIGN.md ที่ root ของโปรเจกต์
     brand-*    สีแบรนด์และสีที่แตกออกมา (hover, พื้นอ่อน, ขอบ, focus)
     on-brand*  ข้อความบนพื้นสีแบรนด์ (แถบต้อนรับ, ปุ่ม, ไอคอนทึบ)
     tone-*     คู่สีสถานะ -bg / -fg ของไอคอนการ์ดตัวเลข (-fg ผ่าน 3:1 บน -bg)
                tone-red-surface/-border/-strong = การ์ดที่ต้องลงมือ (ถูกตีกลับ)
     neutral-*  สถานะว่าง (ตัวเลขเป็น 0)
     danger / success  ปุ่มและป้ายสถานะ — ตรงกับ --bs-*-rgb ของ Bootstrap
     shadow-* / overlay  เงาและฉากหลังมืด
   ข้อยกเว้นที่ตั้งใจ: สีโลโก้/ปุ่ม Microsoft (ต้องตาม brand guideline) และกล่อง debug
   ===================================================================== */
:root {
    --brand: #1f4e79;            /* น้ำเงินกรมท่า — contrast AA บนพื้นขาว */
    --brand-hover: #173c5e;
    --brand-soft: #e8f0f8;
    --accent: #c9a227;           /* ทองสำหรับ active indicator */
    --sidebar-bg: #14263b;
    --sidebar-text: #c5d1de;
    --sidebar-muted: #7f93a8;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-active: rgba(255, 255, 255, .11);
    --body-bg: #f3f5f8;
    --surface: #ffffff;
    --border: #e1e6ed;
    --text: #1f2933;
    --text-muted: #5f6b7a;
    --navbar-h: 62px;
    --sidebar-w: 256px;
    --sidebar-w-collapsed: 68px;
    --radius: 12px;

    /* แบรนด์ (ต่อ) */
    --brand-deep: #24598a;        /* ปลาย gradient แถบต้อนรับ */
    --brand-tint: #f5f9fd;        /* พื้นอ่อนมาก: แจ้งเตือนที่ยังไม่อ่าน */
    --brand-border: #b9cfe5;      /* ขอบการ์ดงานที่รอดำเนินการ */
    --focus-border: #7fa3c7;
    --focus-ring: rgba(31, 78, 121, .2);
    --selection: #cfe0f1;
    --on-brand: #fff;
    --on-brand-muted: #e8eff6;    /* ข้อความรองบนพื้นแบรนด์ — ≥4.7:1 */

    /* เส้นและข้อความกลาง */
    --border-strong: #aab4bf;
    --muted-strong: #4b5663;

    /* สถานะ — คู่ bg/fg ของไอคอน */
    --tone-blue-bg: #e3f0fc;   --tone-blue-fg: #1565c0;
    --tone-green-bg: #e5f4ea;  --tone-green-fg: #2e7d32;
    --tone-teal-bg: #e0f2ef;   --tone-teal-fg: #0f6b63;
    --tone-amber-bg: #fff4dc;  --tone-amber-fg: #a15c00;  --tone-amber-border: #f0cf8a;
    --tone-red-bg: #fdecec;    --tone-red-fg: #c62828;
    --tone-red-surface: #fff5f5; --tone-red-border: #f1b0b0; --tone-red-strong: #b42318;
    --tone-slate-bg: #eef1f4;  --tone-slate-fg: #546170;
    --neutral-icon-bg: #f1f3f6; --neutral-icon-fg: #6b7785;
    --danger: #b91c1c;
    --danger-strong: #991b1b;
    --success: #157347;

    /* เงาและฉากหลัง */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-lg: 0 10px 30px rgba(16, 24, 40, .08);
    --overlay: rgba(15, 23, 42, .45);
    --sidebar-divider: rgba(255, 255, 255, .06);

    --bs-primary: var(--brand);
    --bs-primary-rgb: 31, 78, 121;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 31, 78, 121;
    --bs-link-hover-color: var(--brand-hover);
    --bs-body-font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --bs-body-color: var(--text);
    /*
     * --bs-body-bg คือสีพื้นของ card, ตาราง, input, dropdown ใน Bootstrap — ต้องเป็นขาว (surface)
     * ไม่ใช่สีพื้นหน้า ไม่งั้นทุก card/ตารางจะกลืนกับหน้าและข้อความรองตก contrast
     * สีพื้นหน้าตั้งที่ body โดยตรงด้านล่าง
     */
    --bs-body-bg: var(--surface);
    --bs-body-bg-rgb: 255, 255, 255;

    /* สีข้อความของ Bootstrap ปรับให้ผ่าน 4.5:1 แม้วางบนพื้นหน้า (#f3f5f8) ไม่ใช่แค่บนขาว */
    --bs-secondary-color: var(--text-muted);
    --bs-secondary-rgb: 95, 107, 122;     /* .text-secondary  #5f6b7a */
    --bs-danger-rgb: 185, 28, 28;         /* .text-danger     #b91c1c */
    --bs-success-rgb: 21, 115, 71;        /* .text-success    #157347 */
    --bs-code-color: #a3235f;             /* <code> เดิม #d63384 */
}

html, body { min-height: 100%; }
body { background: var(--body-bg); color: var(--text); font-size: 15px; }

.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-hover); --bs-btn-hover-border-color: var(--brand-hover);
    --bs-btn-active-bg: var(--brand-hover); --bs-btn-active-border-color: var(--brand-hover);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-hover); --bs-btn-active-border-color: var(--brand-hover);
}
/* ปุ่ม outline ของ Bootstrap ใช้ hex ตายตัว (#6c757d / #dc3545) ซึ่งต่ำกว่า 4.5:1 บนพื้นหน้า — ใช้สีที่ผ่านแทน */
.btn-outline-secondary {
    --bs-btn-color: var(--text-muted); --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-color: var(--on-brand); --bs-btn-hover-bg: var(--text-muted); --bs-btn-hover-border-color: var(--text-muted);
    --bs-btn-active-color: var(--on-brand); --bs-btn-active-bg: var(--muted-strong); --bs-btn-active-border-color: var(--muted-strong);
}
.btn-outline-danger {
    --bs-btn-color: var(--danger); --bs-btn-border-color: var(--danger);
    --bs-btn-hover-color: var(--on-brand); --bs-btn-hover-bg: var(--danger); --bs-btn-hover-border-color: var(--danger);
    --bs-btn-active-color: var(--on-brand); --bs-btn-active-bg: var(--danger-strong); --bs-btn-active-border-color: var(--danger-strong);
}
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--focus-border); box-shadow: 0 0 0 .2rem var(--focus-ring);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.text-brand { color: var(--brand) !important; }
::selection { background: var(--selection); color: var(--text); }
.min-w-0 { min-width: 0; }
.skip-link { position: absolute; left: 1rem; top: .5rem; z-index: 2000; background: var(--surface); padding: .5rem 1rem; border-radius: 8px; }

/* ---------------------------------------------------------------- Navbar */
.app-navbar {
    position: fixed; inset: 0 0 auto 0; height: var(--navbar-h); z-index: 1030;
    display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.btn-icon {
    width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--text-muted);
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem; position: relative;
}
.btn-icon:hover, .btn-icon[aria-expanded="true"] { background: var(--brand-soft); color: var(--brand); }
.brand { display: flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--text); min-width: 0; }
/* โลโก้คณะเศรษฐศาสตร์ (econ-sdg-icon.png) — มีสีของตัวเอง จึงวางบนพื้นโปร่ง ไม่ใส่กรอบสีแบรนด์ */
.brand-logo { width: 36px; height: 36px; object-fit: contain; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-title { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: .74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navbar-end { margin-left: auto; display: flex; align-items: center; gap: .35rem; flex-shrink: 0; }
.user-menu {
    display: flex; align-items: center; gap: .6rem; border: 0; background: transparent;
    padding: .3rem .5rem; border-radius: 10px; color: var(--text); text-align: left;
}
.user-menu:hover { background: var(--brand-soft); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-weight: 600; font-size: .9rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: .75rem; color: var(--text-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-header { max-width: 280px; }

/* Notification */
.notif-count {
    position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--tone-red-fg); color: var(--on-brand); font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center;
}
.notif-menu { width: 340px; max-width: calc(100vw - 1.5rem); padding: 0; overflow: hidden; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: .65rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: .88rem; }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--brand-soft); }
.notif-item strong { font-weight: 500; }
.notif-item.unread { background: var(--brand-tint); }
.notif-item.unread strong { font-weight: 700; }
.notif-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--brand); margin-right: .4rem; vertical-align: .1em; }
.notif-item .notif-time { display: block; font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.notif-empty { padding: 1.5rem 1rem; text-align: center; color: var(--text-muted); font-size: .88rem; }

/* --------------------------------------------------------------- Sidebar */
.app-shell { padding-top: var(--navbar-h); }
.app-sidebar {
    position: fixed; top: var(--navbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 1020;
    background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
    transition: width .2s ease, transform .2s ease;
}
.side-nav { list-style: none; margin: 0; padding: .25rem .6rem .75rem; flex: 1; }
.side-item { margin-bottom: 2px; }
.side-link {
    display: flex; align-items: center; gap: .75rem; width: 100%; padding: .55rem .75rem;
    border: 0; border-radius: 9px; background: transparent; color: var(--sidebar-text);
    text-decoration: none; text-align: left; font-size: .93rem; position: relative; white-space: nowrap;
}
a.side-link:hover { background: var(--sidebar-hover); color: var(--on-brand); }
.side-item.active > .side-link { background: var(--sidebar-active); color: var(--on-brand); font-weight: 600; }
.side-item.active > .side-link::before {
    content: ''; position: absolute; left: -.6rem; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.side-icon { font-size: 1.05rem; width: 1.25rem; text-align: center; flex-shrink: 0; }
.side-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.side-item.planned .side-link { color: var(--sidebar-muted); cursor: default; }
.badge-phase {
    font-size: .68rem; font-weight: 600; padding: .1rem .4rem; border-radius: 6px;
    background: rgba(255, 255, 255, .08); color: var(--sidebar-muted);
}
.side-heading { padding: 1rem .75rem .35rem; font-size: .72rem; letter-spacing: .05em; color: var(--sidebar-muted); list-style: none; }
.side-footer { padding: .75rem 1.35rem; font-size: .72rem; color: var(--sidebar-muted); border-top: 1px solid var(--sidebar-divider); }
.sidebar-backdrop { display: none; }

/* ------------------------------------------------------------------ Main */
.app-main {
    margin-left: var(--sidebar-w); min-height: calc(100vh - var(--navbar-h));
    padding: 1.5rem 1.75rem 0; display: flex; flex-direction: column; transition: margin-left .2s ease;
}
.app-main:focus { outline: none; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { margin-bottom: .35rem; font-size: .85rem; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--brand); }
.app-footer {
    margin-top: auto; padding: 1.25rem 0; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    font-size: .82rem; color: var(--text-muted); border-top: 1px solid var(--border);
}
.app-main > .card, .app-main > .row, .app-main > section { margin-bottom: 1.5rem; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 .85rem; }
.card-soft { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* Collapsed (desktop) */
@media (min-width: 992px) {
    html.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }
    html.sidebar-collapsed .app-main { margin-left: var(--sidebar-w-collapsed); }
    html.sidebar-collapsed .side-label,
    html.sidebar-collapsed .badge-phase { display: none !important; }
    html.sidebar-collapsed .side-heading { padding: .6rem 0 .2rem; border-top: 1px solid var(--sidebar-divider); margin-top: .4rem; }
    html.sidebar-collapsed .side-link { justify-content: center; padding: .6rem 0; }
    html.sidebar-collapsed .side-footer { display: none; }
}

/* Mobile / tablet: sidebar เป็น off-canvas */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: none; }
    html.sidebar-open .app-sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
    html.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: var(--navbar-h) 0 0 0; background: var(--overlay); z-index: 1010; }
    .app-main { margin-left: 0; padding: 1.1rem 1rem 0; }
    .brand-sub { display: none; }
}
@media (max-width: 575.98px) {
    .user-meta { display: none; }
    .brand-title { font-size: .95rem; }
    .page-title { font-size: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar, .app-main { transition: none; }
}

/* ------------------------------------------------------------- Dashboard */
.welcome-card {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
    background: linear-gradient(120deg, var(--brand) 0%, var(--brand-deep) 100%); color: var(--on-brand);
    border-radius: var(--radius); padding: 1.25rem 1.5rem;
}
.welcome-hello { font-size: 1.2rem; font-weight: 700; margin: 0 0 .25rem; }
.welcome-meta { margin: 0; font-size: .9rem; color: var(--on-brand-muted); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.scope-pill { background: rgba(255, 255, 255, .16); border-radius: 999px; padding: .1rem .6rem; font-size: .8rem; }
.period-box { display: flex; flex-direction: column; text-align: right; background: rgba(255, 255, 255, .12); border-radius: 10px; padding: .6rem 1rem; }
.period-label { font-size: .75rem; color: var(--on-brand-muted); }
.period-value { font-weight: 700; font-size: 1.05rem; }
.period-due { font-size: .78rem; color: var(--on-brand-muted); }
@media (max-width: 575.98px) { .period-box { text-align: left; width: 100%; } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.stat-card {
    display: flex; gap: .9rem; align-items: flex-start; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem;
}
.stat-icon { width: 44px; height: 44px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-weight: 600; font-size: .92rem; }
.stat-hint { font-size: .78rem; color: var(--text-muted); }
.tone-brand .stat-icon { background: var(--brand-soft); color: var(--brand); }
.tone-blue .stat-icon { background: var(--tone-blue-bg); color: var(--tone-blue-fg); }
.tone-green .stat-icon { background: var(--tone-green-bg); color: var(--tone-green-fg); }
.tone-teal .stat-icon { background: var(--tone-teal-bg); color: var(--tone-teal-fg); }
.tone-amber .stat-icon { background: var(--tone-amber-bg); color: var(--tone-amber-fg); }
.tone-red  .stat-icon { background: var(--tone-red-bg); color: var(--tone-red-fg); }
.tone-slate .stat-icon { background: var(--tone-slate-bg); color: var(--tone-slate-fg); }
@media (max-width: 575.98px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
    .stat-card { flex-direction: column; gap: .5rem; padding: .85rem; }
    .stat-icon { width: 36px; height: 36px; font-size: 1.05rem; }
    .stat-value { font-size: 1.35rem; }
    .stat-hint { display: none; }
}
/*
 * สีของการ์ดตัวเลขบอกลำดับความสำคัญ ไม่ใช่การตกแต่ง
 * - is-zero    ไม่มีรายการ → ถอยเป็นสีเทาทั้งใบ ให้สีไปอยู่เฉพาะที่มีของ
 * - is-pending งานในคิวที่รอ "ผู้ใช้คนนี้" ทำ → พื้นน้ำเงินอ่อนทั้งใบ (สีแบรนด์ = ต้องลงมือ)
 * - is-alert   คำขอที่ถูกตีกลับ → พื้นแดงอ่อน (ผู้ยื่นต้องแก้)
 */
/* ความกว้างคอลัมน์ของตารางในฟอร์ม (inline style ใช้ไม่ได้เพราะ CSP) */
#author-table th:nth-child(1) { width: 32%; }
#author-table th:nth-child(2) { width: 30%; }
#author-table th:nth-child(3),
#author-table th:nth-child(4) { width: 16%; }
#thesis-table th:nth-child(1) { width: 30%; }
#thesis-table th:nth-child(2) { width: 45%; }
#thesis-table th:nth-child(3) { width: 15%; }
.col-select { width: 2.5rem; }

.stat-card.is-zero .stat-icon { background: var(--neutral-icon-bg); color: var(--neutral-icon-fg); }
.stat-card.is-zero .stat-value { color: var(--text-muted); }
.stat-card.is-pending { background: var(--brand-soft); border-color: var(--brand-border); }
.stat-card.is-pending .stat-icon { background: var(--brand); color: var(--on-brand); }
.stat-card.is-pending .stat-value { color: var(--brand); }
.stat-card.is-alert.tone-red { background: var(--tone-red-surface); border-color: var(--tone-red-border); }
.stat-card.is-alert.tone-red .stat-value { color: var(--tone-red-strong); }
.stat-card.is-alert.tone-amber { border-color: var(--tone-amber-border); }

/* ---------------------------------------------------------------- Profile */
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
.info-list dt { font-weight: 500; color: var(--text-muted); }
.info-list dd { margin: 0; word-break: break-word; }
@media (max-width: 575.98px) { .info-list { grid-template-columns: 1fr; } .info-list dd { margin-bottom: .4rem; } }
.perm-list { list-style: none; padding: 0; margin: 0; columns: 1; font-size: .9rem; }
.perm-list li { padding: .25rem 0; border-bottom: 1px dashed var(--border); }
.perm-list code { font-size: .75rem; color: var(--text-muted); }

/* ------------------------------------------------------------ Auth/Error */
.auth-body { background: radial-gradient(1200px 600px at 10% -10%, #dce8f4 0%, transparent 60%), var(--body-bg); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card {
    width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 2rem 1.75rem; box-shadow: var(--shadow-lg);
}
.auth-card-wide { max-width: 560px; }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-mark {
    width: 56px; height: 56px; border-radius: 15px; background: var(--brand); color: var(--on-brand); font-size: 1.6rem;
    display: inline-flex; align-items: center; justify-content: center; margin-bottom: .75rem;
}
.auth-mark-dev { background: var(--tone-slate-fg); }
.auth-logo { display: block; width: 64px; height: 64px; object-fit: contain; margin: 0 auto .75rem; }
.auth-title { font-size: 1.3rem; font-weight: 700; margin: 0 0 .35rem; }
.auth-sub { color: var(--text-muted); font-size: .9rem; margin: 0; }
.auth-hint { font-size: .8rem; color: var(--text-muted); text-align: center; margin: .75rem 0 0; }
.auth-dev { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px dashed var(--border); }
.auth-footer { margin-top: 1.25rem; font-size: .8rem; color: var(--text-muted); }
.btn-ms {
    display: flex; align-items: center; justify-content: center; gap: .75rem; padding: .7rem 1rem;
    background: #fff; color: #1f1f1f; border: 1px solid #8c8c8c; border-radius: 8px; font-weight: 600;
}
.btn-ms:hover { background: #f3f3f3; color: #1f1f1f; border-color: #6b6b6b; }
.ms-logo { display: grid; grid-template-columns: 9px 9px; gap: 2px; }
.ms-logo span { width: 9px; height: 9px; }
.ms-logo span:nth-child(1) { background: #f25022; }
.ms-logo span:nth-child(2) { background: #7fba00; }
.ms-logo span:nth-child(3) { background: #00a4ef; }
.ms-logo span:nth-child(4) { background: #ffb900; }
.dev-user-list { max-height: 380px; overflow-y: auto; }
.error-icon { font-size: 2.6rem; color: var(--brand); }
.error-code { font-size: .85rem; letter-spacing: .1em; color: var(--text-muted); margin: .25rem 0; }
.error-debug {
    text-align: left; margin-top: 1.25rem; padding: .75rem; background: #1f2933; color: #f8d7da;
    border-radius: 8px; font-size: .72rem; max-height: 300px; overflow: auto; white-space: pre-wrap;
}

/* =====================================================================
   หน้าสาธารณะ (layouts/public) — อ่านได้โดยไม่ต้อง login
   ===================================================================== */
.public-body { background: var(--surface); }

.public-navbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .75rem clamp(1rem, 5vw, 3rem);
    border-bottom: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 0; z-index: 1020;
}
.public-navbar .brand { color: var(--text); }
.public-nav { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.public-navbar .brand { flex: 1 1 auto; }
.public-nav-docs.active { color: var(--text); text-decoration: none; font-weight: 600; }
@media (max-width: 575.98px) {
    .public-navbar { gap: .5rem; }
    .public-nav-docs { display: none; }
    .public-navbar .brand-sub { display: none; }
}

.public-main { max-width: 960px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) 1rem 3rem; }

.public-footer {
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
    max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 2rem;
    border-top: 1px solid var(--border); font-size: .875rem; color: var(--text-muted);
}

.public-hero { padding-bottom: 1rem; border-bottom: 1px solid var(--border); margin-bottom: 2rem; }
.hero-eyebrow { color: var(--text-muted); font-size: .9rem; margin-bottom: .35rem; }
.hero-title { font-size: clamp(1.5rem, 4vw, 2.25rem); font-weight: 700; line-height: 1.3; margin-bottom: .75rem; }
.hero-lead { color: var(--text-muted); max-width: 44rem; margin-bottom: 1.25rem; }
.hero-rate {
    display: inline-flex; flex-direction: column; gap: .15rem;
    background: var(--brand-soft); border-radius: var(--radius);
    padding: .75rem 1.25rem; margin-bottom: 1.25rem;
}
.hero-rate-label { font-size: .85rem; color: var(--text-muted); }
.hero-rate-value { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; }

.public-section { margin-bottom: 2.5rem; }

.step-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.step-card {
    position: relative; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem 1rem 1rem;
}
.step-no {
    position: absolute; top: -.6rem; left: 1rem;
    width: 1.6rem; height: 1.6rem; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand); color: var(--on-brand); font-size: .8rem; font-weight: 600;
}
.step-icon { font-size: 1.4rem; color: var(--brand); display: block; margin-bottom: .4rem; }
.step-label { font-weight: 600; margin-bottom: .25rem; }
.step-detail { font-size: .875rem; color: var(--text-muted); margin: 0; }

.rule-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.rule-list li { display: flex; gap: .5rem; align-items: flex-start; padding: .4rem 0; }

.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-list li {
    display: flex; gap: .75rem; align-items: flex-start;
    padding: .75rem 0; border-bottom: 1px solid var(--border);
}
.doc-list li:last-child { border-bottom: 0; }
.doc-list .bi { color: var(--brand); font-size: 1.1rem; line-height: 1.4; }
.doc-cat { margin-left: auto; font-size: .8rem; color: var(--text-muted); white-space: nowrap; }

/* ------------------------------------------------- หลักเกณฑ์และแบบฟอร์ม */
.docs-lead { color: var(--text-muted); max-width: 44rem; margin-bottom: 1rem; text-wrap: pretty; }
.docs-tip {
    display: flex; gap: .75rem; align-items: flex-start; max-width: 44rem;
    background: var(--brand-tint); border: 1px solid var(--brand-border); border-radius: var(--radius);
    padding: .85rem 1rem; margin-bottom: 1.75rem;
}
.docs-tip p { color: var(--text); text-wrap: pretty; }
.docs-tip-icon { color: var(--brand); font-size: 1.15rem; line-height: 1.5; }
.docs-tip-link { font-weight: 600; text-decoration: none; }
.docs-tip-link:hover { text-decoration: underline; }
.docs-group { margin-bottom: 1.25rem; overflow: hidden; }
.docs-group-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
    padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.docs-group-head .bi { color: var(--brand); }
.docs-group-count { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.docs-rows { list-style: none; padding: 0; margin: 0; }
.doc-row {
    position: relative; display: flex; gap: .9rem; align-items: center;
    padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
    transition: background-color .15s ease;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--brand-tint); }
.doc-row:focus-within { outline: 2px solid var(--brand); outline-offset: -2px; }
.doc-file {
    flex-shrink: 0; width: 44px; height: 52px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand); font-size: .72rem; font-weight: 700; letter-spacing: .04em;
}
.doc-file .bi { font-size: 1.3rem; }
.doc-body { flex: 1 1 auto; min-width: 0; }
.doc-title { font-weight: 600; color: var(--text); text-decoration: none; }
.doc-title:focus-visible { outline: none; }
.doc-row:hover .doc-title { color: var(--brand); text-decoration: underline; text-underline-offset: .2em; }
.doc-desc { margin: .15rem 0 0; font-size: .9rem; color: var(--text-muted); }
.doc-meta { margin: .25rem 0 0; font-size: .8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.doc-open {
    flex-shrink: 0; font-size: .85rem; font-weight: 600; color: var(--brand); white-space: nowrap;
    display: inline-flex; align-items: center; gap: .3rem;
}
@media (max-width: 575.98px) {
    .doc-row { align-items: flex-start; padding: .85rem 1rem; }
    .doc-file { width: 38px; height: 46px; }
    .doc-open { display: none; }
    .docs-group-head { padding: .8rem 1rem; }
}
@media (prefers-reduced-motion: reduce) { .doc-row { transition: none; } }

/* การ์ดคิวงานบน dashboard เป็นลิงก์ — ไม่ให้ขีดเส้นใต้และคงสีข้อความเดิม */
a.stat-card { text-decoration: none; color: inherit; }
a.stat-card:hover { border-color: var(--brand); }
a.stat-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* =====================================================================
   ฟอร์มยื่นคำขอ 8 ขั้น และหน้ารายละเอียด
   ===================================================================== */
.wizard-steps {
    display: flex; flex-wrap: wrap; gap: .4rem;
    list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: none;
}
.wizard-step { flex: 1 1 11rem; }
.wizard-step a {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text-muted); text-decoration: none; font-size: .875rem;
}
.wizard-step a:hover { border-color: var(--brand); color: var(--brand); }
.wizard-no {
    flex: 0 0 auto; width: 1.5rem; height: 1.5rem; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--border); color: var(--text); font-size: .75rem; font-weight: 600;
}
.wizard-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wizard-step.is-current a { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.wizard-step.is-current .wizard-no { background: var(--brand); color: var(--on-brand); }
.wizard-step.is-done .wizard-no { background: var(--success); color: var(--on-brand); }

.upload-block { padding: .9rem 0; border-bottom: 1px solid var(--border); }
.upload-block:last-child { border-bottom: 0; padding-bottom: 0; }
.upload-block input[type="file"] { max-width: 18rem; }

.file-list { list-style: none; padding: 0; margin: .6rem 0 0; }
.file-list li {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    padding: .35rem 0; font-size: .9rem;
}
.file-list .bi { color: var(--brand); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    position: relative; display: flex; gap: .75rem;
    padding: 0 0 1rem 1.1rem; border-left: 2px solid var(--border);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-dot {
    position: absolute; left: -.42rem; top: .25rem;
    width: .7rem; height: .7rem; border-radius: 50%; border: 2px solid var(--surface);
}

/* ตารางผู้แต่ง/วิทยานิพนธ์ — ช่องตัวเลขไม่ต้องกว้างเท่าช่องข้อความ */
#author-table input[type="number"], #thesis-table input[type="number"] { max-width: 8rem; }

/* รายการย่อยของ "หน้าปกใน" ในใบตรวจองค์ประกอบ (เอกสารแนบท้าย 1) */
.component-children {
    margin: .25rem 0 .5rem 1.6rem;
    padding-left: .75rem;
    border-left: 2px solid var(--border);
}
.component-children .form-check { font-size: .9rem; }

/* =====================================================================
   รายการตรวจของเจ้าหน้าที่
   ===================================================================== */
/* ---------------------------------------------- แบบตรวจของเจ้าหน้าที่ (10 ข้อ) */
.checklist { overflow: visible; }
.checklist-head { padding: 1rem 1.1rem .9rem; border-bottom: 1px solid var(--border); }
.checklist-count { font-size: .85rem; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.checklist-progress {
    display: flex; height: 6px; margin-top: .65rem; border-radius: 999px; overflow: hidden; background: var(--neutral-icon-bg);
}
.checklist-progress span { flex: 0 0 0; flex-grow: 0; transition: flex-grow .2s ease; }
.checklist-progress .seg-ok { background: var(--success); }
.checklist-progress .seg-bad { background: var(--danger); }
.checklist-progress .seg-na { background: var(--neutral-icon-fg); }
.checklist-body { padding: 0 1.1rem; }

.check-row { padding: .9rem 0; border-bottom: 1px solid var(--border); margin: 0; min-width: 0; }
.check-row:last-child { border-bottom: 0; }
.check-row.is-bad { background: var(--tone-red-surface); margin: 0 -1.1rem; padding-left: 1.1rem; padding-right: 1.1rem; }
.check-legend {
    float: left; width: 100%; display: flex; align-items: flex-start; gap: .55rem; /* float = legend ปกติ ไม่ไปอยู่ในขอบ fieldset ที่เพิ่มช่องว่าง */
    font-size: .95rem; font-weight: 600; margin-bottom: .3rem; line-height: 1.45;
}
.check-label { flex: 1 1 auto; min-width: 0; }
.check-no {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    min-width: 1.6rem; height: 1.6rem; padding: 0 .3rem; border-radius: 999px;
    background: var(--neutral-icon-bg); color: var(--neutral-icon-fg); font-size: .78rem; font-weight: 700;
    font-variant-numeric: tabular-nums; transition: background-color .15s, color .15s;
}
.check-row.is-ok .check-no { background: var(--success); color: var(--on-brand); }
.check-row.is-bad .check-no { background: var(--danger); color: var(--on-brand); }
.check-row.is-na .check-no { background: var(--muted-strong); color: var(--on-brand); }
.check-detail { clear: left; padding-left: 2.15rem; }
.check-hint { font-size: .85rem; color: var(--text-muted); margin: 0 0 .35rem; }
.check-auto { font-size: .82rem; color: var(--text-muted); margin: 0 0 .5rem; }
.check-evidence { display: flex; flex-wrap: wrap; gap: .4rem .5rem; align-items: center; margin: 0 0 .55rem; }
.evidence-link {
    display: inline-flex; align-items: center; gap: .35rem; min-height: 32px; padding: .2rem .65rem;
    border: 1px solid var(--brand-border); border-radius: 8px; background: var(--brand-tint);
    color: var(--brand); font-size: .85rem; font-weight: 600; text-decoration: none;
}
.evidence-link:hover { background: var(--brand-soft); border-color: var(--brand); }
.evidence-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.evidence-meta { font-weight: 400; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.evidence-missing {
    display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem; border-radius: 8px;
    background: var(--tone-red-surface); border: 1px solid var(--tone-red-border);
    color: var(--tone-red-strong); font-size: .85rem; font-weight: 600;
}
.evidence-note { flex-basis: 100%; margin: 0; font-size: .85rem; color: var(--text); }
.evidence-note .bi { color: var(--brand); margin-right: .25rem; }
.check-controls { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; }
.check-seg {
    display: inline-flex; flex-shrink: 0; border: 1px solid var(--border-strong); border-radius: 8px;
    overflow: hidden; background: var(--surface);
}
.check-opt {
    display: inline-flex; align-items: center; gap: .3rem; min-height: 36px; padding: .25rem .8rem;
    font-size: .88rem; font-weight: 600; color: var(--text-muted); cursor: pointer; user-select: none;
    border-left: 1px solid var(--border); transition: background-color .15s, color .15s;
}
.check-seg .check-opt:first-of-type { border-left: 0; }
.check-opt:hover { background: var(--brand-tint); color: var(--text); }
.btn-check:checked + .check-opt-ok { background: var(--success); color: var(--on-brand); }
.btn-check:checked + .check-opt-bad { background: var(--danger); color: var(--on-brand); }
.btn-check:checked + .check-opt-na { background: var(--muted-strong); color: var(--on-brand); }
.btn-check:focus-visible + .check-opt { outline: 2px solid var(--brand); outline-offset: -3px; }
.btn-check:disabled + .check-opt { cursor: not-allowed; opacity: .6; }
.btn-check:disabled + .check-opt:hover { background: transparent; color: var(--text-muted); }
.check-note { flex: 1 1 14rem; max-width: 26rem; }
.check-meta { font-size: .78rem; color: var(--text-muted); margin: .4rem 0 0; }
.checklist-footer {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
    padding: .75rem 1.1rem; background: var(--surface); border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 16px rgba(16, 24, 40, .06);
}
.checklist-summary { font-size: .88rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.checklist-dirty { color: var(--tone-amber-fg); }
@media (max-width: 575.98px) {
    .check-detail { padding-left: 0; }
    .check-seg { width: 100%; }
    .check-opt { flex: 1 1 0; justify-content: center; padding: .25rem .4rem; }
    .check-note { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
    .checklist-progress span, .check-no, .check-opt { transition: none; }
}

/* =====================================================================
   หน้าผู้ดูแลระบบ
   ===================================================================== */
.perm-module {
    float: none; width: auto;
    font-size: .8rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .03em; color: var(--text-muted);
    border-bottom: 1px solid var(--border); padding-bottom: .2rem; margin-bottom: .4rem;
}
.setting-row { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-meta { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }
.setting-meta code { font-size: .78rem; }
.audit-json {
    background: var(--body-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .75rem; font-size: .8rem; max-height: 22rem; overflow: auto; white-space: pre-wrap;
    word-break: break-word;
}

/* ---------------------------------------------------------------------
   ตัวสลับภาษา TH | EN (topbar, หน้า login, หน้าสาธารณะ)
   --------------------------------------------------------------------- */
.lang-switch {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    padding: 2px;
    background: var(--bs-body-bg);
    font-size: .8rem;
    line-height: 1;
}
.lang-option {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 32px; min-width: 36px;
    padding: .3rem .6rem;
    border-radius: 999px;
    color: var(--bs-secondary-color);
    text-decoration: none;
    font-weight: 600;
}
.lang-option:hover { color: var(--brand); }
.lang-option.active {
    background: var(--brand);
    color: var(--on-brand);
}
.navbar-end .lang-switch { margin-right: .5rem; }
@media (pointer: coarse) { .lang-option { min-height: 40px; min-width: 44px; } }
.auth-lang { display: flex; justify-content: flex-end; width: 100%; max-width: 420px; margin: 0 auto .75rem; }
.public-nav .lang-switch { margin-right: .25rem; }
