/* ===== ฟอนต์ IBM Plex Sans Thai (เก็บในเครื่อง ไม่ต้องพึ่งอินเทอร์เน็ต) ===== */
@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-500-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
/* Sarabun ใช้กับหน้าพิมพ์เอกสาร */
@font-face { font-family: "Sarabun"; font-weight: 400; src: url("../fonts/sarabun-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-weight: 400; src: url("../fonts/sarabun-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Sarabun"; font-weight: 700; src: url("../fonts/sarabun-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-weight: 700; src: url("../fonts/sarabun-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --black: #111111; --black-2: #1c1c1e; --black-3: #2a2a2d;
  --yellow: #ffc700; --yellow-2: #ffd84d; --yellow-soft: #fff6d1;
  --ink: #17171a; --muted: #6b6b73; --line: #e7e5df; --bg: #f5f4ef; --card: #ffffff;
  --ok: #157347; --ok-bg: #e3f4ea; --bad: #b42318; --bad-bg: #fdecea; --warn: #8a5a00; --warn-bg: #fff6d1;
  --radius: 14px; --shadow: 0 1px 2px rgba(17,17,17,.04), 0 4px 16px rgba(17,17,17,.05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: "Plex Thai", Tahoma, sans-serif; font-size: 15px; line-height: 1.55; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--yellow); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--black); }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 .2rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); }
.muted.small, div.small { font-size: .8em; margin-top: .1rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== โครงหน้า: แถบข้างสีดำ ===== */
body.has-shell { display: grid; grid-template-columns: 260px 1fr; background: linear-gradient(to right, var(--black) 260px, var(--bg) 260px); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow: hidden; background: var(--black); color: #d8d8dc;
  display: flex; flex-direction: column; padding: .8rem .8rem; gap: .6rem; }
.sidebar a { color: inherit; text-decoration: none; }
.brand { flex: none; display: flex; align-items: center; gap: .6rem; padding: .1rem .3rem .2rem; }
.brand img { width: 34px; height: 34px; }
.brand span { font-weight: 700; font-size: 1rem; color: #fff; line-height: 1.15; }
.brand small { display: block; font-weight: 500; font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }
.co-card { flex: none; background: var(--black-2); border: 1px solid var(--black-3); border-radius: 12px; padding: .55rem .7rem; }
.co-label { font-size: .7rem; color: #8d8d95; }
.co-name { color: #fff; font-weight: 600; font-size: .88rem; line-height: 1.25; margin: .1rem 0 0; }
.co-meta { margin-top: .35rem; font-size: .76rem; color: #a9a9b0; display: flex; align-items: center; gap: .4rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5a5a60; display: inline-block; }
.dot.on { background: var(--yellow); box-shadow: 0 0 0 3px rgba(255,199,0,.18); }
.co-switch { display: inline-block; margin-top: .5rem; font-size: .82rem; color: var(--yellow) !important; }
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #3a3a40 transparent; }
.nav a, .nav span.disabled { display: flex; align-items: center; gap: .6rem; padding: .38rem .65rem; border-radius: 9px; font-size: .88rem; font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: var(--black-2); color: #fff; }
.nav a.active { background: var(--yellow); color: var(--black); font-weight: 600; }
.nav span.disabled { color: #5c5c63; cursor: default; }
.nav svg, .logout svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-soon { font-size: .72rem; color: #66666d; padding: .55rem .65rem .2rem; }
.side-foot { flex: none; margin-top: 0; border-top: 1px solid var(--black-3); padding-top: .8rem; display: flex; flex-direction: column; gap: .6rem; font-size: .88rem; }
.side-foot > a { color: #a9a9b0; padding: 0 .4rem; display: flex; align-items: center; gap: .45rem; }
.side-foot > a svg { width: 16px; height: 16px; flex: none; }
.side-foot > a:hover { color: var(--yellow); }
.me { display: flex; align-items: center; gap: .6rem; padding: 0 .2rem; }
.me a { flex: 1; color: #fff; font-weight: 500; line-height: 1.2; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.me small { display: block; color: #8d8d95; font-weight: 400; font-size: .76rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--yellow); color: var(--black); font-weight: 700; display: grid; place-items: center; flex: none; }
.me form { margin: 0; }
.logout { background: none; border: 0; color: #8d8d95; cursor: pointer; padding: .35rem; border-radius: 8px; }
.logout:hover { color: var(--yellow); background: var(--black-2); }

main { min-width: 0; max-width: 1240px; width: 100%; margin: 0 auto; padding: 2rem 2.2rem 3rem; }

/* ===== หัวหน้า ===== */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.eyebrow { font-size: .82rem; color: var(--muted); font-weight: 600; margin-bottom: .2rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: .9rem 1.1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* ===== ตัวเลขสรุป ===== */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 1.6rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem 1.1rem; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .k { color: var(--muted); font-size: .86rem; font-weight: 500; }
.stat .v { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.stat .u { font-size: .8rem; color: var(--muted); }
.stat.hero { background: var(--black); border-color: var(--black); color: #fff; }
.stat.hero .k, .stat.hero .u { color: #a9a9b0; }
.stat.hero .v { color: var(--yellow); }
.stat.hero::after { content: ""; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; border: 14px solid rgba(255,199,0,.12); }

/* ===== ปุ่ม ===== */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1.5px solid var(--yellow); background: var(--yellow); color: var(--black) !important;
  border-radius: 10px; padding: .5rem 1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; line-height: 1.3; transition: transform .08s, background .15s, box-shadow .15s; }
.btn:hover { background: var(--yellow-2); box-shadow: 0 4px 14px rgba(255,199,0,.35); }
.btn:active { transform: translateY(1px); }
.btn.dark { background: var(--black); border-color: var(--black); color: #fff !important; }
.btn.dark:hover { background: var(--black-3); box-shadow: none; }
.btn.secondary { background: #fff; border-color: #d7d5ce; color: var(--ink) !important; }
.btn.secondary:hover { border-color: var(--black); box-shadow: none; }
.btn.danger { background: #fff; color: var(--bad) !important; border-color: #f0c5c1; }
.btn.danger:hover { border-color: var(--bad); box-shadow: none; }
.btn.small { padding: .25rem .6rem; font-size: .86rem; border-radius: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

/* ===== ตาราง ===== */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .7rem; border-bottom: 1px solid #efede8; vertical-align: top; text-align: left; }
th { font-size: .82rem; font-weight: 600; color: var(--muted); background: #fbfaf7; white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fffbea; }
tbody tr:last-child td { border-bottom: 0; }
tr.void td { color: #a3a3aa; }
tr.void td a { text-decoration: line-through; }
tfoot td { font-weight: 700; border-top: 2px solid var(--black); background: #fbfaf7; }
td a { font-weight: 600; white-space: nowrap; }
td.wide { min-width: 150px; }
.filters .btn { padding: .62rem 1rem; }

/* ===== สถานะ ===== */
.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.draft { color: #6b6b73; background: #efeee9; }
.badge.issued { color: #7a5600; background: var(--yellow-soft); }
.badge.paid { color: var(--ok); background: var(--ok-bg); }
.badge.partial { color: #1d4e89; background: #e6effa; }
.badge.void { color: var(--bad); background: var(--bad-bg); }
.badge.sent, .badge.ordered { color: #7a5600; background: var(--yellow-soft); }
.badge.accepted { color: var(--ok); background: var(--ok-bg); }
.badge.rejected { color: var(--bad); background: var(--bad-bg); }
.badge.closed { color: #44444a; background: #e6e5df; }

/* ===== ข้อความแจ้ง ===== */
.messages { list-style: none; padding: 0; margin: 0 0 1.2rem; }
.messages li { padding: .7rem 1rem; border-radius: 10px; margin-bottom: .45rem; border-left: 4px solid; background: #fff; box-shadow: var(--shadow); }
.messages .success { border-color: var(--ok); }
.messages .info { border-color: var(--yellow); }
.messages .warning { border-color: var(--warn); }
.messages .error { border-color: var(--bad); color: var(--bad); }
.note { padding: .75rem 1rem; border-radius: 10px; background: var(--yellow-soft); color: #5c4300; border: 1px solid #f3dc8a; margin-bottom: 1.1rem; }

/* ===== ฟอร์ม ===== */
label { display: block; font-size: .84rem; font-weight: 500; color: var(--muted); margin-bottom: .3rem; }
input, select, textarea { width: 100%; font: inherit; padding: .52rem .7rem; border: 1.5px solid #dedcd5; border-radius: 10px; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--black); box-shadow: 0 0 0 4px rgba(255,199,0,.35); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; padding: 0; flex: none; accent-color: var(--black); }
input:disabled, select:disabled { background: #f3f2ee; color: var(--muted); }
.field { margin-bottom: .2rem; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.errorlist { color: var(--bad); margin: .25rem 0; padding-left: 1rem; font-size: .86rem; }
.check { display: flex; gap: .5rem; align-items: center; padding-top: 1.6rem; }
.check label { margin: 0; color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; margin-bottom: 1rem; }
.filters > div { min-width: 170px; }

/* ===== ตารางรายการในฟอร์มเอกสาร ===== */
.lines td { padding: .45rem .4rem; border-bottom: 1px solid #f1efea; }
.lines input, .lines select { padding: .4rem .5rem; border-radius: 8px; }
.lines .w-desc { min-width: 160px; }
.lines .w-unit { width: 70px; }
.lines .js-qty { width: 72px; }
.lines .js-price { width: 100px; }
.lines .js-qty, .lines .js-price { text-align: right; }
.lines .js-amount { font-weight: 600; padding-top: .9rem; }
.lines tr.deleted { display: none; }
.totals { margin-left: auto; max-width: 400px; }
.totals div { display: flex; justify-content: space-between; padding: .28rem 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .2rem; }
.totals .net { background: var(--black); color: var(--yellow); border-radius: 10px; padding: .6rem .8rem; border: 0; font-size: 1.1rem; }
[hidden] { display: none !important; }
.dep-box { margin: .5rem 0 1rem; padding: .7rem .8rem; border: 1px dashed var(--line); border-radius: 10px; }
.dep-box h3 { margin: 0; font-size: 1rem; }
.dep-row { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .9rem; padding: .55rem 0 .2rem;
  border-top: 1px solid var(--line); margin-top: .45rem; }
.dep-info { flex: 1 1 13rem; min-width: 0; }
.dep-avail { white-space: nowrap; font-variant-numeric: tabular-nums; }
.dep-in { display: flex; gap: .4rem; align-items: center; }
.dep-in input { width: 9rem; text-align: right; }
.inst-card { margin: 1rem 0; }
.inst-bar { display: flex; height: .55rem; border-radius: 99px; background: var(--line); overflow: hidden; margin: .2rem 0 .45rem; }
.inst-bar .done { background: var(--black); }
.inst-bar .draft { background: var(--yellow); }
.inst-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem .8rem; margin-top: .8rem; }
.inst-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; }
.inst-form input { width: 8rem; text-align: right; }
.inst-form .muted { flex-basis: 100%; }
.cert-links { font-size: .78rem; margin-top: .2rem; white-space: nowrap; color: var(--muted, #777); }
.cert-links a { font-weight: 600; }

/* ===== หน้าเข้าสู่ระบบ ===== */
.no-shell main { max-width: none; padding: 0; margin: 0; }
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: var(--black); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art img { width: 64px; }
.auth-art h2 { font-size: 2.3rem; line-height: 1.25; font-weight: 700; margin: 0 0 .8rem; letter-spacing: -.02em; max-width: 15ch; }
.auth-art h2 em { font-style: normal; color: var(--yellow); }
.auth-art p { color: #a9a9b0; max-width: 40ch; margin: 0; }
.auth-art .big-mark { position: absolute; right: -90px; bottom: -70px; width: 420px; opacity: .08; }
.auth-art .foot { font-size: .8rem; color: #66666d; }
.auth-form { display: grid; place-items: center; padding: 2rem; }
.auth-form .box { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 1.8rem; }
.auth-form .btn { width: 100%; justify-content: center; padding: .7rem; margin-top: .6rem; }
.auth-form .field { margin-bottom: .9rem; }

/* ===== เลือกบริษัท ===== */
.co-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.co-tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); text-decoration: none; transition: transform .15s, box-shadow .15s, border-color .15s; }
.co-tile:hover { transform: translateY(-2px); border-color: var(--black); box-shadow: 0 10px 30px rgba(17,17,17,.1); }
.co-tile .ini { width: 44px; height: 44px; border-radius: 12px; background: var(--black); color: var(--yellow); font-weight: 700; font-size: 1.2rem; display: grid; place-items: center; margin-bottom: .9rem; }
.co-tile .t { font-weight: 600; font-size: 1.05rem; }
.co-tile .s { color: var(--muted); font-size: .86rem; margin-top: .2rem; }
.co-tile .tags { margin-top: .8rem; display: flex; gap: .4rem; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .8rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.quick { display: flex; flex-wrap: wrap; gap: .6rem; }

/* ===== จอเล็ก / มือถือ: แถบข้างกลายเป็นแถบบน ===== */
@media (max-width: 900px) {
  body.has-shell { display: block; background: var(--bg); }
  .sidebar { position: static; height: auto; overflow: visible; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .7rem 1rem; gap: .6rem; }
  .brand { padding: 0; } .brand img { width: 32px; height: 32px; }
  .co-card, .nav-soon, .nav span.disabled, .side-foot > a { display: none; }
  .nav { flex-direction: row; overflow-x: auto; overflow-y: visible; flex: none; width: 100%; order: 3; }
  .nav a { white-space: nowrap; padding: .45rem .7rem; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .me a { display: none; }
  main { padding: 1.2rem 1rem 2rem; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 2rem; min-height: 220px; }
  .auth-art h2 { font-size: 1.6rem; }
}
.login-box { max-width: 420px; margin: 6vh auto; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.logo-preview { height: 110px; border: 1.5px dashed #d7d5ce; border-radius: 12px; display: grid; place-items: center; margin-bottom: 1rem; background: #fbfaf7; }
.logo-preview img { max-height: 90px; max-width: 80%; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }

/* ===== เมนูแบบกลุ่ม (ดรอปดาวน์) ===== */
.nav-group summary { list-style: none; display: flex; align-items: center; gap: .6rem; padding: .38rem .65rem; border-radius: 9px;
  font-size: .88rem; font-weight: 500; cursor: pointer; user-select: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary:hover { background: var(--black-2); color: #fff; }
.nav-group summary.in, .nav-group[open] summary { color: #fff; background: var(--black-2); }
.nav-group .chev { margin-left: auto; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s; opacity: .7; }
.nav-group[open] .chev { transform: rotate(45deg); }
.nav .sub { padding: .3rem .65rem .3rem 1.9rem; font-size: .84rem; position: relative; }
.nav .sub svg { width: 16px; height: 16px; }
.nav .code { margin-left: -.35rem; opacity: .6; font-size: .9em; font-weight: 500; letter-spacing: .01em; }
.nav .sub::before { display: none; }
.nav span.sub.disabled { color: #5c5c63; }
@media (max-width: 900px) {
  .burger { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 10px; background: var(--black-2);
    color: #fff; cursor: pointer; margin-left: 0; order: -1; }
  .sidebar > .side-foot { display: none; }
  .nav-me { display: block; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid #2c2c32; }
  .nav-me .who { display: flex; align-items: center; gap: .6rem; padding: .4rem .7rem; color: #fff; font-size: .88rem; }
  .nav-me .who small { display: block; color: #9a9aa2; font-size: .75rem; }
  .nav-me .lo { display: flex; align-items: center; gap: .55rem; width: 100%; text-align: left; padding: .55rem .7rem; background: none; border: 0; color: #ff8a8a; font: inherit; font-size: .88rem; cursor: pointer; }
  .burger svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
  .side-foot { margin: 0; }
  .nav { display: none; position: fixed; z-index: 60; top: 0; left: 0; bottom: 0; width: min(72vw, 270px); order: 0;
    flex-direction: column; flex-wrap: nowrap; overflow-y: auto; overflow-x: hidden; background: var(--black);
    padding: 1rem .8rem 2rem; gap: .15rem; box-shadow: 8px 0 30px rgba(0,0,0,.45); }
  body.nav-open .nav { display: flex; }
  .nav-bg { display: none; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }
  body.nav-open .nav-bg { display: block; }
  body.nav-open { overflow: hidden; }
  .nav a, .nav-group summary { padding: .55rem .7rem; font-size: .88rem; gap: .55rem; }
  .nav svg { width: 20px; height: 20px; }
  .nav .sub svg { width: 17px; height: 17px; }
  .nav .sub { padding: .45rem .7rem .45rem 1.9rem; font-size: .82rem; }
  .nav span.sub.disabled { display: none; }
}
.badge.pending { color: #7a5600; background: var(--yellow-soft); }
.badge.approved { color: var(--ok); background: var(--ok-bg); }
.nav-group summary.sel, .nav-group[open] summary.sel { background: var(--yellow); color: var(--black); font-weight: 600; }
.co-head { display: flex; align-items: center; gap: .7rem; }
.co-logo { flex: none; width: 36px; height: 36px; border-radius: 10px; background: #fff; object-fit: contain; padding: 3px; }
.co-logo.ini { background: var(--yellow); color: var(--black); font-weight: 700; font-size: .95rem; letter-spacing: .02em; display: grid; place-items: center; padding: 0; }
.co-text { min-width: 0; }
.co-tile .ini.logo { background: #fff; border: 1px solid var(--line); padding: 4px; }
.co-tile .ini.logo img { max-width: 100%; max-height: 100%; object-fit: contain; }

.burger, .nav-bg { display: none; }
@media (max-width: 900px) { .burger { display: grid; } }

.nav-me { display: none; }
@media (max-width: 900px) { .nav-me { display: block; } }

.page-head h1 { display: flex; align-items: center; gap: .7rem; }
.ph-ic { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--yellow); color: var(--black); box-shadow: 0 4px 12px rgba(245,200,66,.35); }
.ph-ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 900px) { .ph-ic { width: 36px; height: 36px; border-radius: 10px; } .ph-ic svg { width: 19px; height: 19px; } }

/* ===== รูปโปรไฟล์ ===== */
.avatar { overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pf-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.1rem; }
.pf-av { width: 72px; height: 72px; font-size: 1.6rem; box-shadow: 0 0 0 4px var(--yellow-soft); }
.pf-head .kv { grid-template-columns: 110px 1fr; }

/* ===== หัวเมนูมือถือ (รูป ชื่อ หน้าแรก | ตั้งค่า + บริษัท) แบบ TRCloud ===== */
.nav-head, .nh-co { display: none; }
@media screen and (max-width: 900px) {
  .nav-head { display: flex; align-items: center; gap: .75rem; padding: .2rem .35rem .85rem; margin: 0 0 .55rem; border-bottom: 1px solid #2c2c32; }
  .nh-av { width: 52px; height: 52px; font-size: 1.3rem; box-shadow: 0 0 0 3px #2c2c32; }
  .nh-text { min-width: 0; }
  .nh-name { color: #fff; font-weight: 700; font-size: 1.02rem; letter-spacing: .03em; text-transform: uppercase; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nh-links { display: flex; align-items: center; gap: .45rem; margin-top: .3rem; font-size: .8rem; color: #55555c; }
  .nav .nh-links a, .nav .nh-co a { display: inline; padding: 0; border-radius: 0; font-size: inherit; font-weight: 500; color: #a9a9b0; background: none; }
  .nav .nh-links a:hover, .nav .nh-links a.active { color: var(--yellow); background: none; }
  .nh-co { display: flex; align-items: center; gap: .55rem; padding: .5rem .55rem; margin: 0 0 .6rem; background: var(--black-2);
    border: 1px solid var(--black-3); border-radius: 10px; }
  .nh-co .co-logo { width: 30px; height: 30px; border-radius: 8px; font-size: .78rem; }
  .nh-co-t { min-width: 0; line-height: 1.25; }
  .nh-co-t b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: #fff; font-size: .8rem; font-weight: 600; }
  .nh-co-t small { display: block; color: #8d8d95; font-size: .72rem; margin-top: .1rem; }
  .nav .nh-co a, .nav .nh-co a:hover, .nav .nh-co a.active { color: var(--yellow); background: none; }
}

/* ===== มือถือ: ย่อทุกหน้าให้กระชับ (เฉพาะหน้าจอ ไม่กระทบตอนพิมพ์) ===== */
@media screen and (max-width: 900px) {
  body { font-size: 14px; }
  main { padding: .9rem .8rem 2rem; }
  h1 { font-size: 1.22rem; line-height: 1.3; }
  h2 { font-size: .98rem; margin: 1rem 0 .5rem; }
  .page-head { gap: .6rem; margin-bottom: .9rem; }
  .page-head h1 { gap: .55rem; }
  .ph-ic { width: 32px; height: 32px; border-radius: 9px; box-shadow: 0 3px 8px rgba(245,200,66,.3); }
  .ph-ic svg { width: 17px; height: 17px; }
  .eyebrow { font-size: .72rem; margin-bottom: .1rem; }
  .page-head .muted { font-size: .78rem; line-height: 1.45; }
  .card { padding: .85rem .9rem; margin-bottom: .8rem; border-radius: 12px; }
  .grid { gap: .6rem .8rem; }
  .btn { padding: .42rem .8rem; font-size: .86rem; border-radius: 9px; }
  .btn.small { padding: .22rem .55rem; font-size: .78rem; }
  .actions { gap: .4rem; }
  label { font-size: .76rem; margin-bottom: .2rem; }
  /* ช่องกรอก 16px: ต่ำกว่านี้ iPhone จะซูมหน้าเองตอนแตะ */
  input, select, textarea { font-size: 16px; padding: .4rem .6rem; line-height: 1.35; border-radius: 9px; }
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: 2.35rem; }
  input[type=month], input[type=date] { -webkit-appearance: none; appearance: none; min-width: 0; min-height: 2.35rem; display: block; text-align: left; }
  input::-webkit-date-and-time-value { text-align: left; }
  .field .help { font-size: .72rem; }
  .errorlist { font-size: .78rem; }
  .check { padding-top: .2rem; }
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .6rem; align-items: end; margin-bottom: .8rem; }
  .filters > div { min-width: 0; }
  .filters .btn { width: 100%; justify-content: center; text-align: center; min-height: 2.35rem; padding: .35rem .6rem; }
  th, td { padding: .5rem .55rem; }
  th { font-size: .7rem; }
  /* ตารางบนมือถือ: ไม่ตัดคำในช่อง (เลื่อนซ้าย-ขวาแทน) ยกเว้นช่องข้อความยาว (ชื่อ/รายการ) */
  td { font-size: .84rem; white-space: nowrap; }
  td.wide { min-width: 150px; white-space: normal; }
  .lines td { white-space: normal; }
  .badge { font-size: .68rem; padding: .1rem .45rem; }
  .messages li, .note { padding: .55rem .75rem; font-size: .82rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; margin-bottom: 1rem; }
  .stat { padding: .7rem .8rem .75rem; border-radius: 12px; }
  .stat .k { font-size: .74rem; }
  .stat .v { font-size: 1.15rem; margin-top: .1rem; }
  .stat .u { font-size: .7rem; }
  .stat.hero::after { width: 70px; height: 70px; border-width: 9px; right: -20px; top: -20px; }
  .totals { font-size: .86rem; }
  .totals .net { font-size: .95rem; padding: .5rem .7rem; }
  .kv { grid-template-columns: 105px 1fr; font-size: .84rem; gap: .25rem .6rem; }
  .lines td { padding: .35rem .3rem; }
  .lines input, .lines select { padding: .3rem .4rem; }
  .co-tile { padding: .9rem; }
  .co-tile .t { font-size: .95rem; }
  .co-tile .s { font-size: .78rem; }
  .pf-av { width: 60px; height: 60px; font-size: 1.35rem; }
  .pf-head .kv { grid-template-columns: 95px 1fr; }
  .sidebar { padding: .5rem .8rem; }
  .burger { width: 38px; height: 38px; }
  .brand img { width: 28px; height: 28px; }
  .brand span { font-size: .92rem; }
  .brand small { font-size: .6rem; }
}

/* ===== ช่องเลือกสินค้า/บริการในบรรทัดเอกสาร ===== */
.head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.lines .col-item { min-width: 210px; }
.lines .js-item-search { min-width: 200px; }
.lines .js-item-search.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(200,40,40,.12); }
.item-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.item-tags:empty { display: none; }
.item-tags span { font-size: .72rem; line-height: 1.4; padding: 0 .4rem; border-radius: 6px; background: #f3f2ee; color: var(--muted); white-space: nowrap; }
.ip-menu { position: absolute; z-index: 1000; max-width: min(92vw, 520px); max-height: 300px; overflow-y: auto; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(0,0,0,.16); padding: 4px; }
.ip-opt { display: grid; grid-template-columns: auto 1fr; gap: 0 .6rem; width: 100%; text-align: left; background: none; border: 0;
  border-radius: 8px; padding: .45rem .55rem; font: inherit; color: var(--ink); cursor: pointer; }
.ip-opt:hover, .ip-opt.on { background: var(--yellow-soft, #fff6cc); }
.ip-code { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .86rem; color: var(--muted); }
.ip-name { font-size: .92rem; }
.ip-name small { color: var(--muted); }
.ip-tags { grid-column: 2; font-size: .74rem; color: var(--muted); }
.ip-empty { padding: .5rem .6rem; font-size: .82rem; color: var(--muted); }
.lines-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
.vat-mix { margin: .3rem 0 .8rem; }
@media (max-width: 900px) {
  .lines .col-item { min-width: 180px; }
  .lines .js-item-search { min-width: 170px; }
  .ip-opt { padding: .55rem .5rem; }
}
.unit-add { display: flex; align-items: flex-end; gap: .8rem; flex-wrap: wrap; }
.unit-add .field { flex: 1 1 220px; margin: 0; }

/* แท็บหน้าตั้งค่า (ข้อมูลส่วนตัว / ตั้งค่าเอกสาร / ปิดงวด) */
.set-tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin: 0 0 1rem; }
.set-tabs a { display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .85rem; border-radius: 999px; background: #fff; border: 1px solid var(--line, #e3e3e8); color: inherit; font-weight: 500; font-size: .9rem; text-decoration: none; }
.set-tabs a svg { width: 17px; height: 17px; flex: none; }
.set-tabs a.on { background: var(--yellow); border-color: var(--yellow); color: var(--black); font-weight: 600; }
@media (max-width: 900px) { .set-tabs a { font-size: .85rem; padding: .4rem .7rem; } }

/* ===== โมดูลบัญชี (GL) ===== */
.m-only, .gl-toggle, .m-inline { display: none; }
.gl-roles .field label { font-weight: 600; }
.tb td.tb-acc, .tb td.tb-acc a { white-space: normal; }
@media screen and (max-width: 900px) {
  /* ตารางหลายคอลัมน์ -> แถวละการ์ด: บรรทัด 1 = วันที่ เลขที่/บัญชี ยอดเงิน · บรรทัด 2 = คำอธิบาย ยอดคงเหลือ */
  .mrows thead { display: none; }
  .mrows, .mrows tbody, .mrows tfoot { display: block; width: 100%; }
  .mrows tr { display: grid; grid-template-columns: auto 1fr auto; gap: .15rem .6rem; padding: .55rem .7rem;
    border-bottom: 1px solid var(--line); align-items: baseline; }
  .mrows td { display: block; padding: 0 !important; border: 0 !important; min-width: 0; white-space: normal; }
  .mrows td a { white-space: normal; }
  .mrows .m-a { grid-row: 1; grid-column: 1; white-space: nowrap; }
  .mrows .m-b { grid-row: 1; grid-column: 2; }
  .mrows .m-ab { grid-row: 1; grid-column: 1 / 3; }
  .mrows .m-amt { grid-row: 1; grid-column: 3; text-align: right; font-weight: 600; white-space: nowrap; }
  .mrows .m-sub { grid-row: 2; grid-column: 1 / 3; color: var(--muted); font-size: .8rem; }
  .mrows .m-sub2 { grid-row: 3; grid-column: 1 / -1; color: var(--muted); font-size: .76rem; }
  .mrows .m-bal { grid-row: 2; grid-column: 3; text-align: right; font-size: .8rem; color: var(--muted); white-space: nowrap; }
  .mrows .m-x, .mrows .m-empty { display: none !important; }
  .mrows .m-dr::before { content: "Dr "; color: var(--muted); font-weight: 400; font-size: .74rem; }
  .mrows .m-cr::before { content: "Cr "; color: var(--muted); font-weight: 400; font-size: .74rem; }
  .mrows tr.m-group { display: block; background: #f6f7f9; }
  /* งบทดลอง: มือถือแสดง บัญชี + คงเหลือ (กด "ดูทุกคอลัมน์" เพื่อเลื่อนดูแบบเต็ม) */
  .tb:not(.show-all) .m-hide { display: none; }
  .tb:not(.show-all) .m-only { display: table-cell; }
  .gl-toggle { display: inline-flex; }
  .m-inline { display: inline; }
  /* บันทึกรายการ: บรรทัดละการ์ด */
  .jv-lines, .jv-lines tbody, .jv-lines tfoot { display: block; width: 100%; }
  .jv-lines thead { display: none; }
  .jv-lines tbody tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: .35rem .5rem; padding: .7rem .6rem;
    border-bottom: 1px solid var(--line); align-items: end; }
  .jv-lines tbody td { display: block; padding: 0 !important; border: 0 !important; min-width: 0; }
  .jv-lines tbody td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted);
    margin-bottom: .1rem; }
  .jv-lines tbody td.j-acc, .jv-lines tbody td.j-ct, .jv-lines tbody td.j-desc { grid-column: 1 / -1; }
  .jv-lines tbody select, .jv-lines tbody input { width: 100%; }
  .jv-lines tfoot tr { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .5rem; padding: .6rem; }
  .jv-lines tfoot td { display: block; padding: 0 !important; border: 0 !important; text-align: left !important; }
  .jv-lines tfoot td.j-foot-btn, .jv-lines tfoot td.j-diff { grid-column: 1 / -1; }
  .jv-lines tfoot td.j-empty { display: none; }
  .jv-lines tfoot td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-weight: 400; font-size: .76rem; }
}

/* ผังบัญชี: บัญชีหัวข้อ */
table.coa tr.coa-head td { background: #faf9f5; }
.badge.head { color: #5a4a00; background: var(--yellow-soft); }
/* รายละเอียดบริษัท / ตราประทับ / QR พร้อมเพย์ */
.stamp-preview img { max-width: 110px; max-height: 110px; }
.kv-wide dt { min-width: 11rem; }
.check { flex-wrap: wrap; }
.check .help { flex-basis: 100%; margin-top: 0; }

/* ลายเซ็นผู้ใช้ (ข้อมูลส่วนตัว) · ผู้ลงนาม (รายละเอียดบริษัท) */
.sig-card h3 { font-size: 1rem; margin: 1.4rem 0 .5rem; }
.sig-now { display: inline-flex; flex-direction: column; align-items: center; padding: .6rem 1.2rem .5rem;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-bottom: 1rem; }
.sig-now img { max-width: 260px; max-height: 90px; }
.sig-name { font-size: .86rem; color: var(--muted); border-top: 1px solid #c9ccd2; padding-top: .25rem; margin-top: .2rem;
  min-width: 200px; text-align: center; }
.sig-label { font-weight: 600; margin-bottom: .4rem; }
.sig-pad { position: relative; width: 100%; max-width: 560px; height: 200px; border: 1.5px dashed #c9ccd2; border-radius: 12px;
  background: #fff; touch-action: none; user-select: none; -webkit-user-select: none; }
.sig-pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.sig-base { position: absolute; left: 8%; right: 8%; top: 72%; border-top: 1px solid #d9dce1; pointer-events: none; }
.sig-hint { position: absolute; left: 8%; top: calc(72% + .3rem); font-size: .78rem; color: #a0a4ab; pointer-events: none; }
.sig-tools { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-top: .55rem; max-width: 560px; }
.sig-tools .btn { margin-left: auto; }
.sig-ink { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.sig-ink i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }
.sig-cos { margin: 0; padding-left: 1.1rem; }
.sig-cos li { margin: .25rem 0; }
.signers { width: 100%; border-collapse: collapse; }
.signers td, .signers th { padding: .55rem .4rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.signers th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.signers .c { text-align: center; }
.signers .sub { font-size: .78rem; color: var(--muted); }
@media (max-width: 640px) {
  .sig-pad { height: 170px; }
  .signers thead { display: none; }
  .signers tr { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .signers td { border: 0; padding: 0; }
  .signers td.c { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
  .signers td.c:last-child { justify-content: flex-end; }
  .signers td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem; }
}
