/* ระบบจัดซื้อ – สโตร์ – โปรเกรส (เวอร์ชัน 2)
   โทนอุ่นชุดเดียวกับระบบเดิม cream canvas + clay accent */

:root {
    --bg: #f4f1ea;
    --surface: #ffffff;
    --surface-2: #f6f3ec;
    --paper: #faf9f5;
    --cream: #ece7da;
    --text: #2a2824;
    --muted: #7d7a70;
    --line: #e7e2d6;
    --clay: #c15f3c;
    --clay-soft: #d97757;
    --clay-dark: #a54c2d;
    --green: #4f8a6b;
    --amber: #b5822e;
    --red: #c0503f;
    --nav: #262521;
    --nav-2: #302e28;
    --shadow: 0 16px 38px rgba(58, 46, 34, .10);
    --shadow-soft: 0 10px 26px rgba(58, 46, 34, .07);
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", Tahoma, Arial, sans-serif;
    background: linear-gradient(180deg, var(--paper) 0%, var(--bg) 260px);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--clay); }

h1, h2, h3 {
    font-family: "Fraunces", Georgia, "Times New Roman", serif;
    font-weight: 600;
    letter-spacing: -.01em;
    margin: 0 0 10px;
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15.5px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.small { font-size: 12.5px; }

/* ---------- layout ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    flex: 0 0 264px;
    width: 264px;
    /* iOS ไม่หักแถบเบราว์เซอร์ออกจาก 100vh ทำให้เมนูล่างสุดโดนทับ dvh แก้จุดนี้ */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--nav);
    color: #f3efe6;
    padding: 18px 12px calc(18px + env(safe-area-inset-bottom, 0px));
}

/* ให้เลื่อนเฉพาะรายการเมนู ส่วนโลโก้อยู่กับที่ และเลื่อนถึงรายการสุดท้ายได้เสมอ */
.sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 8px;
}

.sidebar .brand { flex: 0 0 auto; }

.brand { display: flex; gap: 11px; align-items: center; padding: 4px 8px 20px; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: 11px;
    background: var(--clay);
    color: #fff;
    font-weight: 700;
    letter-spacing: .02em;
    flex: 0 0 auto;
}

.brand-text strong {
    display: block;
    font-family: "Fraunces", Georgia, serif;
    font-size: 14.5px;
    line-height: 1.25;
}
.brand-text small { color: #a8a496; font-size: 11.5px; }

.nav-group {
    margin: 16px 10px 6px;
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #8f8b7d;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    margin: 2px 0;
    border-radius: 9px;
    color: #ded9cd;
    text-decoration: none;
    font-size: 14px;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}

.nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.nav-item:hover { background: var(--nav-2); color: #fff; transform: translateX(2px); }
.nav-item.active { background: var(--clay); color: #fff; box-shadow: 0 8px 18px rgba(193, 95, 60, .3); }
.nav-item.active svg { opacity: 1; }

/* ป้ายจำนวนงานรอเซ็นข้างเมนู "รออนุมัติ" */
.nav-count {
    margin-left: auto;
    flex: 0 0 auto;
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--clay);
    color: #fff;
    font-size: 11.5px;
    font-weight: 700;
    text-align: center;
    line-height: 1.6;
}
.nav-item.active .nav-count { background: rgba(255, 255, 255, .22); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    background: rgba(250, 249, 245, .9);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
    backdrop-filter: blur(6px);
}

.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h1 { margin: 0; }
.kicker { color: var(--clay); font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; }

.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user .who { text-align: right; line-height: 1.25; }
.topbar-user .who strong { display: block; font-size: 13.5px; }
.topbar-user .who small { color: var(--muted); font-size: 11.5px; }

.nav-burger { display: none; cursor: pointer; }
.nav-burger svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }

.content { flex: 1 1 auto; padding: 22px 24px 40px; max-width: 1500px; width: 100%; }
.foot { padding: 14px 24px calc(26px + env(safe-area-inset-bottom, 0px)); color: var(--muted); font-size: 12px; }

/* ---------- card ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 18px 20px;
    margin: 0 0 18px;
    animation: rise .22s ease both;
}

.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; flex: 1 1 auto; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ---------- stat ---------- */

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--clay);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-soft);
    transition: transform .16s ease, box-shadow .16s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; display: block; margin-bottom: 4px; }
.stat .value { font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 600; }
.stat .hint { color: var(--muted); font-size: 11.5px; }
.stat.ok { border-left-color: var(--green); }
.stat.warn { border-left-color: var(--amber); }
.stat.bad { border-left-color: var(--red); }

/* ---------- สายอนุมัติที่ใช้อยู่ (approvals.php) ---------- */
.chain-now {
    margin: 0 0 14px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius, 12px);
    background: var(--surface-2);
}
.chain-now h3 { margin: 0 0 8px; font-size: 14px; }
.chain-now ol { margin: 0; padding-left: 20px; }
.chain-now li { margin-bottom: 4px; }
.chain-now li.off strong { color: var(--muted); text-decoration: line-through; }

/* ---------- table ---------- */

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; color: #55524a; white-space: nowrap; font-size: 12.5px; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #fbf8f2; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty .emoji { font-size: 30px; display: block; margin-bottom: 6px; opacity: .75; }

/* ---------- form ---------- */

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
label { font-size: 12.5px; color: #55524a; font-weight: 600; }
label .req { color: var(--red); }

input[type=text], input[type=password], input[type=number], input[type=date], input[type=file], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--paper);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

textarea { min-height: 78px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--clay-soft);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(217, 119, 87, .18);
}

.hint { color: var(--muted); font-size: 11.5px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--clay);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, transform .15s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--clay-dark); transform: translateY(-1px); box-shadow: 0 8px 18px rgba(193, 95, 60, .22); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--cream); color: var(--text); box-shadow: none; }
.btn.ok { background: var(--green); }
.btn.ok:hover { background: #3f7357; }
.btn.bad { background: var(--red); }
.btn.bad:hover { background: #a5402f; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

:focus-visible { outline: 2px solid var(--clay-soft); outline-offset: 2px; }

/* ---------- alert / badge ---------- */

.alert {
    border: 1px solid var(--line);
    border-left: 4px solid var(--clay);
    background: var(--surface);
    border-radius: 10px;
    padding: 11px 14px;
    margin: 0 0 14px;
    font-size: 13.5px;
    animation: rise .2s ease both;
}
.alert.ok { border-left-color: var(--green); background: #f2f8f4; }
.alert.warn { border-left-color: var(--amber); background: #fdf6e9; }
.alert.bad { border-left-color: var(--red); background: #fdf1ef; }
.alert.info { border-left-color: var(--clay); background: #fbf4f0; }
.alert strong { font-weight: 700; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge.ok { background: #e8f2ec; color: #35664e; border-color: #cfe3d8; }
.badge.warn { background: #fbf1de; color: #8a621f; border-color: #efdfc0; }
.badge.bad { background: #fbe9e6; color: #963d30; border-color: #f0d2cc; }
.badge.info { background: #f8ece7; color: #9c4c2f; border-color: #eed7cc; }
.badge.muted { background: var(--cream); color: #6a675d; border-color: #ddd7c8; }

.bar { position: relative; height: 8px; border-radius: 99px; background: var(--cream); overflow: hidden; min-width: 90px; }
.bar > span { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .4s ease; }
.bar.over > span { background: var(--red); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 150px; }

.file-link { font-size: 12.5px; }

.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.doc-no { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- checklist (หน้าติดตั้ง) ---------- */

.check-list {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
}

.check-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 2px;
    border-bottom: 1px solid var(--line);
}

.check-list li:last-child { border-bottom: 0; }

.check-icon { flex: 0 0 22px; line-height: 1.4; }

.check-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.check-body strong { font-weight: 600; }
.check-body .small { line-height: 1.4; word-break: break-word; }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.login-card .brand { padding: 0 0 18px; }

/* ตัวคั่นก่อนปุ่มเข้าสู่ระบบด้วย LINE */
.login-or {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 12px;
    color: var(--muted);
    font-size: 12.5px;
}
.login-or::before,
.login-or::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--line); }

.line-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: #06c755;
    border-color: #06c755;
    color: #fff;
}
.line-btn:hover { background: #05b64d; border-color: #05b64d; }
.line-btn svg { width: 20px; height: 20px; fill: currentColor; stroke: none; flex: 0 0 auto; }

/* ---------- responsive ---------- */

.nav-toggle { display: none; }

.nav-scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(38, 37, 33, .45);
    cursor: pointer;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 10px 0 30px rgba(38, 37, 33, .25);
    }
    .nav-toggle:checked ~ .sidebar { transform: none; }
    .nav-toggle:checked ~ .nav-scrim { display: block; }
    .nav-burger { display: inline-flex; }
    .content { padding: 18px 14px 34px; }
    .topbar { padding: 12px 14px; }
}

@media (max-width: 520px) {
    body { font-size: 14px; }
    .topbar-user .who { display: none; }
    .card { padding: 15px 14px; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dd { margin-bottom: 8px; }
}

@media print {
    .sidebar, .topbar-user, .nav-burger, .actions, .foot { display: none !important; }
    .card { box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}


/* =====================================================================
   DESKTOP POLISH — ชั้นสุดท้าย ทับกฎด้านบนด้วยลำดับ cascade
   เป้าหมาย จอ PC ต้องอ่านง่ายและได้สัดส่วน ไม่ใช่แค่ยืดจากมือถือ
   ===================================================================== */

:root {
    --page-max: 1480px;
    --page-gutter: 24px;
}

/* แถบบน เนื้อหา และท้ายหน้า ใช้ระยะขอบสูตรเดียวกัน จึงตรงแนวกันทุกจอ
   และเนื้อหาถูกจัดกึ่งกลางเองเมื่อจอกว้างกว่า --page-max */
.topbar,
.content,
.foot {
    padding-inline: max(var(--page-gutter), calc((100% - var(--page-max)) / 2));
}

.content { max-width: none; }

/* ---- จอโน้ตบุ๊กขึ้นไป ---- */
@media (min-width: 1100px) {
    :root { --page-gutter: 34px; }

    body { font-size: 15px; }
    h1 { font-size: 25px; }
    h2 { font-size: 19px; }

    .topbar { padding-block: 18px; }
    .content { padding-block: 28px 56px; }

    .card { padding: 22px 24px; border-radius: 14px; }
    .card + .card { margin-top: 20px; }

    /* จำนวนคอลัมน์คงที่ ไม่ให้การ์ดแตกเป็นแถวละหลายใบจนอ่านยาก */
    .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

    /* ฟอร์มยาว ๆ จัดเป็นสามคอลัมน์ อ่านเป็นบรรทัดได้ ไม่กระจายเป็นช่องจิ๋ว */
    .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 20px; }

    .stat { padding: 16px 18px; }
    .stat .value { font-size: 26px; }
    .stat .label { font-size: 12.5px; }

    th, td { padding: 11px 14px; }

    .btn { padding: 10px 18px; }
    .btn.small { padding: 7px 12px; }

    /* หน้ารายละเอียดเอกสาร อ่านคู่กันเป็นสองคอลัมน์ */
    .kv { grid-template-columns: minmax(150px, 220px) 1fr; gap: 8px 18px; }
}

/* ---- จอใหญ่ ---- */
@media (min-width: 1600px) {
    :root { --page-gutter: 44px; }
    .form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .content { padding-block: 32px 64px; }
}

/* ---- รายละเอียดที่ทำให้ดูเรียบร้อยขึ้นทุกจอ ---- */

/* หัวการ์ดมีแถบสีนำสายตา แยกส่วนได้ชัดโดยไม่ต้องใส่เส้นหนา */
.card-head {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.card-head h2 {
    position: relative;
    padding-left: 12px;
}

.card-head h2::before {
    position: absolute;
    left: 0;
    top: .18em;
    bottom: .18em;
    width: 3px;
    border-radius: 999px;
    background: var(--clay);
    content: "";
}

/* ตารางอ่านง่ายขึ้นด้วยแถบสลับสีอ่อน ๆ */
tbody tr:nth-child(even) { background: #fdfbf7; }
tbody tr:hover { background: #f8f2ea; }
th { letter-spacing: .01em; }

/* ปุ่มและฟิลด์สูงเท่ากัน ทำให้แถวเครื่องมือดูเป็นระเบียบ */
.filters .btn { min-height: 38px; }
input[type=text], input[type=password], input[type=number], input[type=date], select { min-height: 38px; }

/* แถบบนติดหนึบและมีเงาบาง ๆ เมื่อเลื่อนหน้า */
.topbar { box-shadow: 0 1px 0 var(--line), 0 6px 18px rgba(58, 46, 34, .04); }

/* หน้าเข้าสู่ระบบบนจอใหญ่ ให้การ์ดลอยกลางจออย่างมีระยะ */
@media (min-width: 900px) {
    .login-card { max-width: 430px; padding: 34px 34px 30px; border-radius: 18px; box-shadow: 0 24px 60px rgba(58, 46, 34, .12); }
}

/* พิมพ์รายงานจากจอ PC ให้เต็มหน้ากระดาษ */
@media print {
    .topbar, .content, .foot { padding-inline: 0; }
}

/* =====================================================================
   TYPE & TOUCH PASS — ขนาดตัวหนังสือและการสัมผัส ทุกอุปกรณ์ (2.4.5)
   มือถือ ≤600 · iPad/แท็บเล็ต 700–1099 · PC ≥1100
   ชั้นท้ายสุด กฎที่นี่ชนะชั้นก่อนหน้าด้วยลำดับ cascade
   ===================================================================== */

/* ตัวหนังสือไหลตามความกว้างจอ ไม่เล็กเกินบนมือถือ ไม่บางเกินบน PC
   ภาษาไทยมีวรรณยุกต์ซ้อน ให้ line-height โปร่งขึ้นเล็กน้อยกันตัดหัวอักษร */
body { font-size: clamp(15px, 14.1px + .3vw, 16px); line-height: 1.58; }
h1 { font-size: clamp(21px, 19px + .7vw, 27px); line-height: 1.3; }
h2 { font-size: clamp(17.5px, 16.6px + .3vw, 20px); line-height: 1.35; }
h3 { font-size: clamp(15.5px, 15px + .2vw, 17px); }

.small { font-size: 13px; }
.hint, .stat .hint { font-size: 12.5px; line-height: 1.45; }
label { font-size: 13px; }
table { font-size: 14px; }
th { font-size: 13px; }
.kv { font-size: 14px; }
.alert { font-size: 14px; line-height: 1.5; }
.badge { font-size: 12px; padding: 3px 10px; }
.doc-no { font-size: 13.5px; }
.file-link { font-size: 13px; }
.stat .label { font-size: 12.5px; }
.stat .value { font-size: clamp(23px, 20px + 1vw, 28px); line-height: 1.2; }
.nav-item { font-size: 14.5px; }
.brand-text strong { font-size: 15px; }
.topbar-user .who strong { font-size: 14px; }
.kicker { font-size: 12px; }
.foot { font-size: 12.5px; }
.empty { font-size: 14.5px; }

/* จอสัมผัส (มือถือ/แท็บเล็ตทุกยี่ห้อ): ช่องกรอกต้องไม่เล็กกว่า 16px
   ไม่งั้น iOS/Android จะซูมเด้งเข้าหาช่องตอนแตะพิมพ์ และปุ่มต้องกดถูกด้วยนิ้วโป้ง */
@media (max-width: 1099px), (pointer: coarse) {
    input[type=text], input[type=password], input[type=number], input[type=date],
    input[type=file], select, textarea {
        font-size: 16px;
        min-height: 46px;
        padding: 11px 13px;
    }
    textarea { min-height: 96px; }
    input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--clay); }
    .btn { min-height: 46px; padding: 11px 18px; font-size: 15.5px; }
    .btn.small { min-height: 38px; padding: 7px 13px; font-size: 13.5px; }
    .nav-item { min-height: 46px; font-size: 15.5px; padding: 11px 12px; }
    .nav-item svg { width: 19px; height: 19px; }
    th, td { padding: 11px 12px; }
    .filters .btn { min-height: 46px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* iPad / แท็บเล็ต: การ์ดสถิติและฟอร์มเรียง 2 คอลัมน์พอดีมือ ไม่บีบเป็นช่องจิ๋ว */
@media (min-width: 700px) and (max-width: 1099px) {
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 18px; }
    .card { padding: 20px 22px; }
    .content { padding-block: 24px 48px; }
}

/* มือถือ: ระยะกระชับแต่ตัวหนังสือใหญ่อ่านชัด ตัวกรองและปุ่มหลักเต็มแถวกดง่าย */
@media (max-width: 600px) {
    /* แถบบนไม่ให้หัวข้อพับหลายบรรทัดจนดันปุ่มตก */
    .topbar { gap: 10px; }
    .topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .kicker { font-size: 11px; }
    .topbar .btn, .topbar-user .btn { min-height: 40px; padding: 8px 13px; font-size: 13.5px; white-space: nowrap; }
    .card { padding: 16px 15px; }
    .card + .card, .card { margin-bottom: 14px; }
    .stat { padding: 14px 15px; }
    .stat .value { font-size: 24px; }
    .kv { font-size: 14.5px; }
    .kv dt { font-size: 13px; }
    .filters { gap: 8px; }
    .filters .field { flex: 1 1 100%; min-width: 0; }
    .filters .btn { width: 100%; justify-content: center; }
    .actions button.btn:not(.small) { flex: 1 1 auto; justify-content: center; }
    .grid { gap: 12px; }
    .form-grid { gap: 12px; }
    .table-wrap { border-radius: 10px; }
    .login-card { padding: 24px 20px; }
}

/* ลูกเล่นเฉพาะจอที่มีเมาส์ และเคารพผู้ใช้ที่ปิดแอนิเมชัน */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .card { transition: transform .16s ease, box-shadow .16s ease; }
    .card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
    .btn:active { transform: translateY(0) scale(.98); }
    tbody tr:hover .btn.ghost.small { border-color: var(--clay-soft); color: var(--clay-dark); }
    .nav-item:active { transform: translateX(2px) scale(.99); }
}

/* ปุ่มกดบนจอสัมผัสให้มีแรงตอบสนองเล็กน้อยแทน hover */
@media (hover: none) {
    .btn:active { background: var(--clay-dark); }
    .btn.ghost:active { background: var(--cream); }
    tbody tr:hover { background: inherit; }
    .card:hover { transform: none; }
}

/* =====================================================================
   NUMBER LEGIBILITY — ตัวเลขต้องอ่านออกทันที (2.4.6)
   เดิมยอดเงินใช้ Fraunces ซึ่งเป็นเซอริฟสำหรับหัวข้อ เส้นบางและเลข 0/6/8
   แยกยากเมื่อเป็นจำนวนยาว ๆ เปลี่ยนมาใช้ Inter ตัวหนา + ตัวเลขความกว้างเท่ากัน
   (tabular-nums) ทำให้หลักตรงกันทุกแถวและกวาดสายตาเทียบตัวเลขได้เร็ว
   ===================================================================== */

.stat .value,
td.num, th.num,
.kv dd,
.doc-no,
.money, .qty {
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ยอดเงินใหญ่บนการ์ดสถิติ อ่านชัดที่สุดในหน้า */
.stat .value {
    font-family: "Inter", "Segoe UI", Tahoma, Arial, sans-serif;
    font-weight: 700;
    letter-spacing: -.015em;
    color: var(--text);
    white-space: nowrap;
    /* จำนวนยาวสุด 15 ตัวอักษร ต้องไม่ล้นการ์ดบนจอ 360px */
    font-size: clamp(21px, 17.5px + 1.15vw, 28px);
    line-height: 1.22;
    display: block;
    margin-bottom: 2px;
}

/* ตัวเลขในตาราง เข้มกว่าข้อความปกติหนึ่งระดับ ให้แยกออกจากตัวหนังสือ */
td.num {
    font-weight: 600;
    color: var(--text);
    font-size: 14.5px;
    letter-spacing: -.005em;
}

/* ยอดรวมท้ายตาราง เป็นตัวเลขสำคัญที่สุดของตาราง */
tfoot th.num, tfoot td.num {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

/* ตัวเลขในหน้ารายละเอียดเอกสาร และเลขที่เอกสาร */
.kv dd { font-size: 14.5px; }
.kv dd strong { font-weight: 700; }
.doc-no {
    font-family: "Inter", "Segoe UI", Tahoma, Arial, sans-serif;
    font-weight: 600;
    letter-spacing: .01em;
    font-size: 14px;
}
.doc-no a { text-decoration: none; border-bottom: 1px solid rgba(193, 95, 60, .35); }
.doc-no a:hover { border-bottom-color: var(--clay); }

/* เปอร์เซ็นต์ข้างแถบโปรเกรส อ่านคู่กับแถบได้ในพริบตา */
.bar + .small, .bar ~ .small { font-weight: 600; color: #5d5a51; font-variant-numeric: tabular-nums; }
.bar { height: 9px; }

/* ตัวเลขบนมือถือ: การ์ดสถิติแคบ ยอดยาวต้องยังอยู่บรรทัดเดียว */
@media (max-width: 600px) {
    .stat .value { font-size: clamp(20px, 4.9vw, 25px); }
    .stat .label { font-size: 13px; font-weight: 600; color: #5d5a51; }
    td.num { font-size: 14.5px; }
    /* ตารางบนมือถือ ตัวเลขไม่ควรถูกบีบจนอ่านยาก ปล่อยให้เลื่อนแนวนอนแทน */
    table { min-width: 100%; }
}

/* จอ PC ตัวเลขใหญ่ขึ้นอีกขั้น เพราะระยะมองไกลกว่ามือถือ */
@media (min-width: 1100px) {
    td.num { font-size: 15px; }
    tfoot th.num, tfoot td.num { font-size: 15.5px; }
    .kv dd { font-size: 15px; }
    .doc-no { font-size: 14.5px; }
}

/* =====================================================================
   DATE FIELD FIX — ช่องวันที่ยาวล้นกรอบบน iPhone/iPad (2.4.7)

   Safari บน iOS คิดความกว้างของ input[type=date] จากเนื้อหาข้างในตัวมันเอง
   (วัน/เดือน/ปี + ปุ่มปฏิทิน) แล้ว "ไม่ยอมหด" ตาม width:100% ที่เราสั่ง
   ช่องจึงดันออกนอกการ์ดและกว้างกว่าช่องอื่นในฟอร์มเดียวกัน
   ต้องรีเซ็ต appearance ของ Safari ทิ้งก่อน ความกว้างที่เราสั่งจึงมีผล
   แก้ที่นี่ที่เดียว มีผลกับช่องวันที่ทุกหน้า (ใบขอซื้อ ใบสั่งซื้อ รับของ
   เบิกของ จ่ายเงิน เงินสดย่อย โปรเกรส กำลังคน คลังเอกสาร)
   ===================================================================== */

input[type=date],
input[type=time],
input[type=datetime-local] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    /* iOS จัดค่าวันที่ไว้กึ่งกลางช่องมาเอง บังคับให้ชิดซ้ายเท่ากับช่องอื่น */
    text-align: left;
}

input[type=date]::-webkit-date-and-time-value,
input[type=time]::-webkit-date-and-time-value,
input[type=datetime-local]::-webkit-date-and-time-value {
    text-align: left;
    /* กันตัวอักษรถูกตัดหัวท้ายหลังรีเซ็ต appearance */
    min-height: 1.4em;
    margin: 0;
}

/* ปุ่มปฏิทินชิดขวาสุดของช่อง ไม่เบียดตัวเลขวันที่ */
input[type=date]::-webkit-calendar-picker-indicator {
    margin-inline-start: auto;
    padding-inline-start: 8px;
    opacity: .5;
    cursor: pointer;
}
input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* ช่องเลือกไฟล์ก็ดันกรอบได้เหมือนกันเมื่อชื่อไฟล์ยาว */
input[type=file] {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

/* =====================================================================
   SORTABLE TABLE — กดหัวคอลัมน์เพื่อเรียงต่ำไปสูง / สูงไปต่ำ (2.4.8)
   หัวคอลัมน์ที่เรียงได้จะมีลูกศรจาง ๆ บอก และเข้มขึ้นเมื่อกำลังเรียงด้วยคอลัมน์นั้น
   class เหล่านี้ใส่โดย assets/app.js ถ้า JS ไม่ทำงานหัวตารางจะเป็นข้อความธรรมดาตามเดิม
   ===================================================================== */

th.sortable {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    padding-right: 26px;
    transition: background .14s ease, color .14s ease;
}

/* ลูกศรสองหัวจาง ๆ บอกว่าคอลัมน์นี้กดเรียงได้ */
th.sortable::after {
    content: "";
    position: absolute;
    right: 9px;
    top: 50%;
    width: 8px;
    height: 11px;
    margin-top: -5.5px;
    opacity: .3;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 8px 11px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='11' viewBox='0 0 8 11'%3E%3Cpath d='M4 0.5 L7 4 H1 Z M4 10.5 L1 7 H7 Z' fill='%2355524a'/%3E%3C/svg%3E");
}

th.sortable:hover { background: var(--cream); color: var(--text); }
th.sortable:hover::after { opacity: .6; }

/* คอลัมน์ที่กำลังเรียงอยู่ หัวเข้มขึ้นและลูกศรชี้ทางเดียวสีธีม */
th.sortable.sort-asc,
th.sortable.sort-desc {
    background: var(--cream);
    color: var(--clay-dark);
}

th.sortable.sort-asc::after,
th.sortable.sort-desc::after {
    opacity: 1;
    width: 9px;
    height: 7px;
    margin-top: -3.5px;
    background-size: 9px 7px;
}

th.sortable.sort-asc::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='7' viewBox='0 0 9 7'%3E%3Cpath d='M4.5 0 L9 7 H0 Z' fill='%23a54c2d'/%3E%3C/svg%3E");
}

th.sortable.sort-desc::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='7' viewBox='0 0 9 7'%3E%3Cpath d='M4.5 7 L0 0 H9 Z' fill='%23a54c2d'/%3E%3C/svg%3E");
}

th.sortable:focus-visible { outline: 2px solid var(--clay-soft); outline-offset: -2px; }

/* บนจอสัมผัส หัวคอลัมน์ต้องกดถูกด้วยนิ้ว */
@media (max-width: 1099px), (pointer: coarse) {
    th.sortable { padding-top: 13px; padding-bottom: 13px; }
}

/* =====================================================================
   CODE DETAIL — กดที่ Cost Code แล้วกางรายละเอียดใต้แถว (2.4.9)
   เนื้อหามาจาก code_detail.php ผ่าน assets/app.js
   ตารางมักกว้างกว่าจอ แผงจึงตรึงขอบซ้ายไว้ (sticky) และ JS บีบความกว้าง
   ให้เท่ากรอบที่มองเห็น ผู้ใช้จะอ่านได้โดยไม่ต้องเลื่อนแนวนอนตาม
   ===================================================================== */

/* ตัวรหัสในตาราง บอกให้รู้ว่ากดได้และกางอยู่หรือไม่ */
a.code-toggle { cursor: pointer; }
a.code-toggle::after {
    content: "▸";
    display: inline-block;
    margin-inline-start: 5px;
    font-size: 11px;
    opacity: .55;
    transition: transform .16s ease, opacity .16s ease;
}
a.code-toggle.code-open::after { transform: rotate(90deg); opacity: 1; }
a.code-toggle.code-open { font-weight: 700; }

.code-detail-row > td {
    padding: 0 !important;
    background: var(--surface-2);
    border-bottom: 2px solid var(--clay-soft);
}
.code-detail-row:hover { background: var(--surface-2) !important; }

.code-detail {
    position: sticky;
    left: 0;
    max-width: 100%;
    padding: 14px 16px 16px;
    animation: cdOpen .18s ease both;
}

@keyframes cdOpen { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.cd-loading { color: var(--muted); font-size: 13.5px; padding: 6px 0; }

.cd-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; margin-bottom: 12px; }
.cd-head .doc-no { font-size: 15px; color: var(--clay-dark); }
.cd-desc { font-weight: 600; }

/* แถบตัวเลขสรุป ไหลตามความกว้างที่มี บนมือถือได้ 2 ช่องต่อบรรทัด */
.cd-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
.cd-stats > div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px 10px;
    min-width: 0;
}
.cd-stats span { display: block; color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.cd-stats b {
    font-weight: 700;
    font-size: 15px;
    font-variant-numeric: tabular-nums lining-nums;
    white-space: nowrap;
}
.cd-stats .cd-ok { color: #35664e; }
.cd-stats .cd-bad { color: #963d30; }

.cd-sec { margin-bottom: 14px; }
.cd-sec:last-of-type { margin-bottom: 10px; }
.cd-sec h4 {
    margin: 0 0 7px;
    font-family: "Inter", "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 13.5px;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.cd-count { font-weight: 500; color: var(--muted); font-size: 12px; }
.cd-empty { margin: 0; color: var(--muted); font-size: 13px; }

/* ตารางย่อยในแผง เลื่อนแนวนอนในกรอบตัวเองเมื่อคอลัมน์เยอะ */
.cd-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
table.cd-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.cd-table th, table.cd-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.cd-table th { background: var(--cream); font-size: 12px; font-weight: 700; white-space: nowrap; }
table.cd-table td.num, table.cd-table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.cd-table td.num { font-weight: 600; }
table.cd-table tbody tr:last-child td { border-bottom: 0; }
table.cd-table tbody tr:nth-child(even) { background: var(--paper); }

.cd-foot { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 600px) {
    .code-detail { padding: 12px 12px 14px; }
    .cd-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cd-stats b { font-size: 14.5px; }
    .cd-foot .btn { flex: 1 1 auto; justify-content: center; }
}

/* =====================================================================
   SIDEBAR POLISH — เมนูซ้ายอ่านง่ายและพอดีจอ (2.8.1)

   ปัญหาเดิมสามข้อ
   1. หัวกลุ่มใช้ text-transform: uppercase คู่กับ letter-spacing ซึ่งเป็นกฎ
      ที่ออกแบบมาสำหรับอังกฤษ พอเป็นภาษาไทย uppercase ไม่มีผลแต่ letter-spacing
      ไปดันสระและวรรณยุกต์ให้ห่างจากพยัญชนะ อ่านแล้วรู้สึกว่าตัวหนังสือแตก
   2. เมนู 18 รายการ 7 กลุ่ม สูงรวม 1044px แต่กรอบมีแค่ ~780px จึงต้องเลื่อนหา
      รายการล่างสุดทุกครั้ง (กลุ่ม "เอกสาร" มีรายการเดียวแต่กินหัวข้อเต็มบรรทัด
      แก้ที่ layout.php โดยย้ายคลังเอกสารไปกลุ่มภาพรวม)
   3. หัวกลุ่มสีจางเกินไปจนแยกกลุ่มไม่ออก
   ===================================================================== */

.sidebar { padding-top: 12px; }
.sidebar nav { padding-bottom: 4px; }

/* โลโก้กระชับลง คืนพื้นที่ให้รายการเมนู */
.brand { padding: 2px 8px 11px; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 13.5px; }
.brand-text strong { font-size: 14px; line-height: 1.3; }
.brand-text small { font-size: 11px; }

/* หัวกลุ่ม: ตัวอักษรไทยต้องไม่ถูกยืด และต้องเห็นชัดว่าเป็นหัวข้อ */
.nav-group {
    margin: 12px 12px 4px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: normal;
    text-transform: none;
    color: #9c9788;
    line-height: 1.25;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* เส้นบาง ๆ ต่อท้ายหัวข้อ แบ่งกลุ่มได้โดยไม่กินความสูง */
.nav-group::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: rgba(243, 239, 230, .10);
}

/* กลุ่มแรกไม่ต้องเว้นบนซ้ำกับระยะของโลโก้ */
.sidebar nav > .nav-group:first-child { margin-top: 2px; }

/* รายการเมนู: กระชับขึ้นเล็กน้อยให้ครบทุกรายการในจอเดียว */
.nav-item {
    padding: 7px 11px;
    margin: 1px 0;
    font-size: 14.5px;
    line-height: 1.35;
    border-radius: 8px;
}

.nav-item svg { width: 18px; height: 18px; opacity: .7; }
.nav-item:hover svg { opacity: 1; }

/* รายการที่เปิดอยู่ ใช้แถบสีด้านซ้ายแทนเงาหนา ๆ ดูสะอาดกว่าและไม่กินที่ */
.nav-item.active {
    background: var(--clay);
    box-shadow: none;
    font-weight: 600;
}
.nav-item.active svg { opacity: 1; }

/* แถบเลื่อนของเมนูให้กลมกลืนกับพื้นเข้ม ไม่ใช่แถบเทาของระบบ */
.sidebar nav { scrollbar-width: thin; scrollbar-color: rgba(243, 239, 230, .22) transparent; }
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(243, 239, 230, .18); border-radius: 99px; }
.sidebar nav:hover::-webkit-scrollbar-thumb { background: rgba(243, 239, 230, .3); }

/* จอสูงพอ ให้เมนูโปร่งขึ้นได้ */
@media (min-height: 940px) {
    .nav-item { padding: 9px 11px; margin: 2px 0; }
    .nav-group { margin-top: 18px; }
}

/* กฎ 46px เป็นของจอสัมผัสและเมนูแบบสไลด์เท่านั้น
   จอโน้ตบุ๊กแคบ ๆ ที่ยังกางเมนูค้างไว้ไม่ควรโดนด้วย ไม่งั้นเมนูยิ่งยาวเกินจอ */
@media (min-width: 901px) and (pointer: fine) {
    .nav-item { min-height: 0; padding: 7px 11px; font-size: 14.5px; }
}

/* จอเตี้ย (โน้ตบุ๊ก 1366x768 และจอที่เปิดแถบเครื่องมือเยอะ)
   บีบระยะลงอีกขั้นให้เห็นรายการได้มากที่สุดก่อนต้องเลื่อน
   ผู้ใช้ที่ไม่ใช่ผู้ดูแลจะเห็นครบทุกรายการในจอเดียวตั้งแต่ขนาดนี้ */
@media (min-width: 901px) and (max-height: 830px) {
    .brand { padding-bottom: 9px; }
    .brand-text small { display: none; }
    .nav-item { padding: 6px 11px; margin: 0; }
    .nav-group { margin-top: 10px; margin-bottom: 3px; }
}

/* =====================================================================
   PERMISSION MATRIX — หน้าตั้งสิทธิ์ (3.3.0)
   ติ๊กเป็นรายการอ่านง่าย ไม่ใช่ตารางกากบาทที่กดพลาดง่ายบนมือถือ
   ===================================================================== */

.perm-group { min-width: 0; }
.perm-group h3 {
    margin: 0 0 8px;
    font-family: "Inter", "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--clay-dark);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.perm-item {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 7px 8px;
    margin: 2px 0;
    border-radius: 8px;
    font-weight: 400;
    cursor: pointer;
    transition: background .14s ease;
}
.perm-item:hover { background: var(--surface-2); }
.perm-item input { flex: 0 0 auto; margin-top: 2px; accent-color: var(--clay); }
.perm-item span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.perm-item strong { font-size: 13.5px; font-weight: 500; line-height: 1.35; }
.perm-item small { font-size: 11.5px; color: var(--muted); }
.perm-item input:checked + span strong { font-weight: 700; }

@media (max-width: 600px) {
    .perm-item { padding: 9px 8px; }
    .perm-item strong { font-size: 14px; }
}

/* ---------- กรอกใบขอซื้อแบบธรรมดา (pr_form.php?mode=plain) ---------- */

.line-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px 14px;
    margin-bottom: 12px;
    background: var(--surface);
}
.line-card.is-here { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(180, 90, 50, .12); }
.line-card.is-sub { margin-left: 18px; border-left: 3px solid var(--brand); }

.line-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--line);
}
.line-head strong { font-size: 15px; }
.line-sub { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.line-sub input { width: auto; margin: 0; }
.line-head [data-del] { margin-left: auto; }

.line-amount {
    padding: 9px 0;
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.sum-table td.num { font-size: 16px; font-weight: 600; }
.sum-table tr.grand th, .sum-table tr.grand td { font-size: 17px; color: var(--brand); }

@media (max-width: 600px) {
    .line-card { padding: 10px 11px 12px; }
    .line-card.is-sub { margin-left: 10px; }
    .line-head [data-del] { margin-left: 0; }
}

/* แถวที่กำลังเปิดดูอยู่ ในตารางรายการทั้งใบ */
tbody tr.is-here > td { background: #fdf3ea; font-weight: 500; }

/* รายการที่ไม่ได้ติ๊กสั่งในหน้าเขียนใบสั่งซื้อ */
.line-card.is-off { opacity: .55; }
.vendor-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.vendor-pick select { max-width: 420px; }

/* ---------- สวิตช์กติกาการเซ็น (approvals.php) ---------- */
.rule-list { display: grid; gap: 10px; margin-bottom: 14px; }
.rule-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}
.rule-item:hover { border-color: var(--brand); }
.rule-item input { width: auto; margin: 2px 0 0; flex: 0 0 auto; }
.rule-item strong { display: block; font-size: 14.5px; }
.rule-item .muted { display: block; margin-top: 2px; }

/* กล่องเติมข้อมูลผู้ขายทีหลัง (po_view.php) */
.vendor-edit {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin: 14px 0 4px;
    background: var(--surface);
}
.vendor-edit > summary { cursor: pointer; font-weight: 600; font-size: 14.5px; color: var(--brand); }
.vendor-edit[open] > summary { margin-bottom: 10px; }

/* ---------- ตั้งค่าเอกสาร (settings.php) ---------- */
.group-title {
    margin: 18px 0 10px;
    font-size: 15px;
    color: var(--brand);
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px;
}
.group-title:first-of-type { margin-top: 4px; }

.head-preview {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}
.hp-logo {
    flex: 0 0 auto;
    width: 92px;
    text-align: center;
    border: 2px solid #1f4e79;
    color: #1f4e79;
    padding: 10px 6px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}
.hp-logo span { display: block; font-size: 8px; letter-spacing: .12em; margin-top: 4px; font-weight: 400; }
.hp-th { font-size: 16px; font-weight: 700; color: #1f4e79; }
.hp-en { font-size: 12.5px; font-weight: 700; color: #1f4e79; }
.hp-addr { font-size: 12px; color: #444; margin-top: 4px; }

@media (max-width: 600px) {
    .head-preview { flex-direction: column; }
}

/* กล่องอนุมัติใบสั่งซื้อ (po_view.php) */
.po-approve {
    border: 2px solid var(--brand);
    border-radius: var(--radius);
    padding: 14px 16px 16px;
    margin: 14px 0;
    background: var(--surface);
}
.po-approve h3 { margin: 0 0 4px; font-size: 16px; color: var(--brand); }
.po-approve .small { margin: 0 0 12px; }

/* กล่องบันทึกสลิปการจ่ายเงิน (po_view.php) */
.slip-box {
    border: 1px solid var(--line);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin: 12px 0;
    background: var(--surface);
}
.slip-box > summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.slip-box[open] > summary { margin-bottom: 10px; }
.inline-form { display: inline; }

/* ปุ่มลบเอกสาร ใช้เฉพาะกับใบที่ยังไม่อนุมัติ */
.btn.danger {
    background: #c0392b;
    border-color: #c0392b;
    color: #fff;
}
.btn.danger:hover { background: #a93226; border-color: #a93226; }


/* =====================================================================
   SIDEBAR POLISH v2 (4.22.0)
   ต่อท้ายไฟล์เพราะกฎเมนูถูกทับกันมาหลายชั้น กฎที่มาทีหลังชนะ
   ใช้เฉพาะ token โทนอุ่นของระบบ ไม่มีสีฟ้า/กรมท่าใหม่
   ===================================================================== */

/* --brand ไม่เคยถูกประกาศใน :root ทั้งที่มีกฎใช้ var(--brand) อยู่หลายที่
   (การ์ดรายการ · สวิตช์กติกาเซ็น · หัวข้อกลุ่มในหน้าตั้งค่า · กล่องอนุมัติใบสั่งซื้อ)
   ค่าที่หายทำให้สีเส้นขอบและตัวอักษรเหล่านั้นหลุดธีมไปเงียบ ๆ */
:root { --brand: var(--clay); --brand-dark: var(--clay-dark); }

/* ---------- กล่องแบรนด์ ---------- */
/* ชื่อระบบยาวจนตัดสองบรรทัด ชนกับคำบรรยายที่ซ้ำความหมายกันเอง
   จัดเป็นบล็อกเดียวมีเส้นคั่น เมนูที่เลื่อนอยู่จะไม่ดูเหมือนถูกตัดกลางคัน */
.sidebar .brand {
    align-items: center;
    gap: 11px;
    margin: 0 2px 10px;
    padding: 2px 6px 12px;
    border-bottom: 1px solid rgba(243, 239, 230, .10);
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    font-size: 14px;
    background: linear-gradient(155deg, var(--clay-soft), var(--clay));
    box-shadow: 0 6px 14px rgba(193, 95, 60, .28);
}

.brand-text { min-width: 0; }
.brand-text strong {
    font-size: 13.5px;
    line-height: 1.3;
    letter-spacing: -.005em;
    color: #f6f2e9;
}
/* คำบรรยายซ้ำกับชื่อระบบอยู่แล้ว เก็บไว้เฉพาะจอที่มีที่เหลือจริง */
.brand-text small { display: none; }
@media (min-height: 900px) {
    .brand-text small { display: block; color: #a29d8e; }
}

/* ---------- หัวกลุ่ม ---------- */
.sidebar .nav-group {
    margin: 15px 12px 5px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    color: #a8a294;
}
.sidebar nav > .nav-group:first-child { margin-top: 4px; }

/* ---------- รายการเมนู ---------- */
.sidebar .nav-item {
    position: relative;
    gap: 11px;
    border-radius: 9px;
    color: #e2ddd1;
    transition: background .16s ease, color .16s ease, padding-left .16s ease;
}

/* แถบสีด้านซ้ายโตจากศูนย์ตอน hover แทนการเลื่อนทั้งแถว
   (เลื่อนแถวทำให้ไอคอนกับตัวอักษรขยับไม่พร้อมกัน ดูสั่น) */
.sidebar .nav-item::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 50%;
    width: 3px;
    height: 0;
    border-radius: 99px;
    background: var(--clay-soft);
    transform: translateY(-50%);
    transition: height .16s ease;
}
.sidebar .nav-item:hover {
    background: var(--nav-2);
    color: #fff;
    transform: none;
    padding-left: 15px;
}
.sidebar .nav-item:hover::before { height: 16px; }

.sidebar .nav-item.active {
    background: linear-gradient(100deg, var(--clay), var(--clay-dark));
    color: #fff;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(193, 95, 60, .26);
}
.sidebar .nav-item.active::before { height: 0; }
.sidebar .nav-item.active:hover { padding-left: 11px; }

/* กดได้ด้วยแป้นพิมพ์ก็ต้องเห็นว่าโฟกัสอยู่ตรงไหน */
.sidebar .nav-item:focus-visible,
.nav-burger:focus-visible {
    outline: 2px solid var(--clay-soft);
    outline-offset: 2px;
}

/* ---------- เมนูที่เลื่อนได้ ---------- */
/* ไล่เฉดจางที่ขอบบน-ล่าง บอกว่ายังมีรายการต่อ ไม่ใช่ถูกตัดทิ้ง
   เป็นสาเหตุที่เมนูดูเพี้ยนตอนเลื่อนค้างอยู่กลางรายการ */
.sidebar nav {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 16px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 16px), transparent 100%);
    padding-right: 2px;
}

/* ---------- จอสัมผัส / เมนูสไลด์ ---------- */
@media (max-width: 900px) {
    .sidebar {
        width: 282px;
        flex-basis: 282px;
        border-radius: 0 18px 18px 0;
        padding-top: 14px;
    }
    /* ปุ่มแตะต้องยังใหญ่พอ (>=44px) แต่ไม่ต้องสูงเท่าปุ่มฟอร์ม */
    .sidebar .nav-item { min-height: 44px; font-size: 15px; padding: 10px 12px; }
    .sidebar .nav-item:hover { padding-left: 16px; }
    .sidebar .nav-item.active:hover { padding-left: 12px; }
    .sidebar .nav-group { margin: 14px 12px 4px; }
    .nav-scrim { backdrop-filter: blur(1.5px); }
}

@media (max-width: 520px) {
    .sidebar { width: 270px; flex-basis: 270px; }
    .brand-text strong { font-size: 13px; }
}

/* เปิดเมนูแล้วไถลเข้ามาอย่างนุ่ม ไม่กระตุก */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar .nav-item,
    .sidebar .nav-item::before { transition: none; }
}


/* =====================================================================
   SIDEBAR FULL-LENGTH (4.23.0)
   เมนูซ้ายยาวเท่าเนื้อหาจริง พื้นหลังเข้มคลุมจนสุดหน้า
   เดิมล็อกความสูงไว้ 100dvh แล้วให้รายการเมนูเลื่อนในกรอบตัวเอง
   พอรายการยาวกว่าจอจึงเห็นแถบเข้มจบกลางทางและรายการถูกตัดหัวตัดท้าย
   ===================================================================== */

/* จอที่กางเมนูค้างไว้ (ตั้งแต่ 901px ขึ้นไป) */
@media (min-width: 901px) {
    /* flex row ยืดลูกให้สูงเท่ากันอยู่แล้ว ปล่อยให้ความสูงงอกตามเนื้อหา
       พื้นหลังเข้มจึงคลุมทั้งหน้าเสมอ ไม่ว่าเมนูหรือเนื้อหาจะยาวกว่ากัน */
    .app { align-items: stretch; }

    .sidebar {
        position: static;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
    }

    /* ไม่ต้องมีสกรอลล์ในเมนูอีก จึงไม่ต้องมีไล่เฉดบอกว่ามีต่อ */
    .sidebar nav {
        overflow: visible;
        -webkit-mask-image: none;
        mask-image: none;
    }

    /* หัวใบยังปักอยู่กับที่ตอนเลื่อนหน้า เมนูจะได้ไม่ลอยไปกับเนื้อหาโดยไม่มีที่อ้างอิง */
    .topbar { position: sticky; top: 0; }
}

/* เมนูสไลด์บนจอสัมผัส ยังต้องอยู่ในกรอบจอ
   ให้เลื่อนทั้งแผงรวมโลโก้ ไม่ใช่เลื่อนแค่รายการข้างใน
   พื้นหลังเข้มติดไปกับแผงจึงไม่มีวันจบกลางทาง */
@media (max-width: 900px) {
    .sidebar {
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    /* ให้ nav สูงเท่าเนื้อหาจริง แล้วปล่อยให้แผงเป็นตัวเลื่อน
       ถ้าปล่อย flex:1 1 auto ไว้ nav จะถูกบีบให้เท่าจอแล้วเนื้อหาล้นออกมาแบบไม่มีตัวเลื่อน */
    .sidebar nav {
        flex: 0 0 auto;
        overflow: visible;
        -webkit-mask-image: none;
        mask-image: none;
    }
}


/* ===================== หน้ากำหนดลายเซ็น ===================== */

.signer-box {
    border: 1px solid var(--line, #e3ded2);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 14px;
    background: #fdfcf9;
}

.signer-box:last-child { margin-bottom: 0; }

.pick-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    padding: 8px 10px;
    border: 1px solid var(--line, #e3ded2);
    border-radius: 8px;
    background: #fff;
    max-height: 220px;
    overflow: auto;
}

.pick {
    display: flex;
    gap: 7px;
    align-items: center;
    font-size: 14px;
    line-height: 1.35;
}

.pick input { margin: 0; }
.pick .small { display: block; }

/* ---------- แถบแท็บล่างของพอร์ทัลพนักงาน ---------- */
/* คนที่กดเข้ามาจากลิงก์ในไลน์จะได้ใช้งานแบบแอป ไม่ต้องเปิดเมนูข้างทุกครั้ง
   ขึ้นเฉพาะจอมือถือ เดสก์ท็อปยังเป็นเมนูข้างเหมือนหน้าอื่นของระบบ
   ใช้ breakpoint 1099px ชุดเดียวกับที่ซ่อนเมนูข้างไปอยู่ใต้ปุ่มขีดสามขีด */
.tabbar { display: none; }

@media (max-width: 1099px), (pointer: coarse) {
    .tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        background: var(--surface);
        border-top: 1px solid var(--line);
        padding: 6px 4px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -8px 24px rgba(58, 46, 34, .10);
    }

    .tabbar-item {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 7px 2px 5px;
        border-radius: 10px;
        text-decoration: none;
        color: var(--muted);
        font-size: 10.5px;
        font-weight: 600;
        line-height: 1.2;
        text-align: center;
    }

    .tabbar-item svg {
        width: 21px;
        height: 21px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.7;
        stroke-linecap: round;
        stroke-linejoin: round;
        opacity: .8;
    }

    .tabbar-item span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* แท็บที่อยู่ตอนนี้ ใช้สีแบรนด์เหมือนเมนูข้างที่ถูกเลือก */
    .tabbar-item.active { color: var(--clay); background: var(--surface-2); }
    .tabbar-item.active svg { opacity: 1; }

    /* กันไม่ให้แถบทับเนื้อหาบรรทัดสุดท้าย และซ่อนท้ายหน้าที่ซ้ำกับแถบ */
    body.has-tabbar .content { padding-bottom: 86px; }
    body.has-tabbar .foot { display: none; }
}

@media print {
    .tabbar { display: none !important; }
}

/* ---------- ปฏิทินรายเดือนของตารางงาน ---------- */
/* ซ้ายเป็นตารางเดือน ขวาเป็นกล่องวันนี้กับเจ็ดวันข้างหน้า
   จอแคบให้ตกลงมาเรียงกันแนวตั้ง และตัวตารางเลื่อนแนวนอนในกรอบตัวเอง
   เจ็ดคอลัมน์บีบให้พอดีจอมือถือแล้วอ่านไม่ออก การเลื่อนอ่านง่ายกว่า */
/* สองคอลัมน์เฉพาะจอที่กว้างพอให้ตารางเดือนไม่ต้องเลื่อนแนวนอน
   แคบกว่านั้นให้กล่องวันนี้กับเจ็ดวันข้างหน้าลงไปอยู่ใต้ปฏิทินแทน */
.cal-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
@media (min-width: 1400px) { .cal-wrap { grid-template-columns: minmax(0, 1fr) 320px; } }
.cal-side { display: flex; flex-direction: column; gap: 18px; }
.cal-main { margin: 0; }
.cal-side .card { margin: 0; }

.cal-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(96px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    min-width: 672px;
}

.cal-head {
    background: var(--clay-dark);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    padding: 9px 4px;
}

.cal-day { background: var(--surface); min-height: 104px; padding: 7px 7px 9px; }
.cal-day.out { background: var(--surface-2); }
.cal-day.out .cal-date { color: #bfb8aa; }
.cal-day.today { background: #fdf3ec; box-shadow: inset 0 0 0 2px var(--clay); }

.cal-date { font-size: 12.5px; font-weight: 700; color: var(--text); margin-bottom: 5px; }
.cal-day.today .cal-date { color: var(--clay-dark); }

.cal-item {
    font-size: 11px;
    line-height: 1.35;
    color: var(--text);
    background: var(--cream);
    border-left: 3px solid var(--clay-soft);
    border-radius: 5px;
    padding: 3px 5px;
    margin-bottom: 4px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}
.cal-item .cal-time { display: block; font-weight: 700; color: var(--clay-dark); font-size: 10px; }

.cal-list { list-style: none; margin: 10px 0 0; padding: 0; }
.cal-list li { padding: 9px 0; border-top: 1px solid var(--line); }
.cal-list li:first-child { border-top: 0; padding-top: 0; }
.cal-list strong { display: block; font-size: 13px; color: var(--text); line-height: 1.4; }
.cal-list span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* จอกว้างปานกลาง วางกล่องข้างเรียงคู่กันใต้ปฏิทิน จะได้ไม่ยาวเกินไป */
@media (min-width: 700px) and (max-width: 1399px) {
    .cal-side { flex-direction: row; }
    .cal-side .card { flex: 1 1 0; min-width: 0; }
}

@media print {
    .cal-scroll { overflow: visible; }
    .cal-grid { min-width: 0; }
}

/* จอมือถือ ย่อช่องปฏิทินลงให้เห็นได้หลายวันขึ้นต่อการเลื่อนหนึ่งครั้ง
   และลดความสูงลง ไม่งั้นตารางเดือนเดียวยาวจนต้องเลื่อนทั้งสองแกน
   ข้อมูลที่ต้องใช้จริงอยู่ในกล่องวันนี้กับเจ็ดวันข้างหน้าที่อยู่ใต้ปฏิทินอยู่แล้ว */
@media (max-width: 699px) {
    .cal-grid { grid-template-columns: repeat(7, minmax(74px, 1fr)); min-width: 518px; }
    .cal-day { min-height: 76px; padding: 5px 5px 7px; }
    .cal-date { font-size: 11.5px; margin-bottom: 3px; }
    .cal-item { font-size: 10px; padding: 2px 4px; -webkit-line-clamp: 2; }
    .cal-head { font-size: 11px; padding: 7px 2px; }
}
