/* ===== ฟอนต์ 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); }
.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-y: auto; background: var(--black); color: #d8d8dc;
  display: flex; flex-direction: column; padding: 1.1rem .9rem; gap: 1rem; }
.sidebar a { color: inherit; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .7rem; padding: .2rem .4rem .6rem; }
.brand img { width: 40px; height: 40px; }
.brand span { font-weight: 700; font-size: 1.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 { background: var(--black-2); border: 1px solid var(--black-3); border-radius: 12px; padding: .75rem .85rem; }
.co-label { font-size: .76rem; color: #8d8d95; }
.co-name { color: #fff; font-weight: 600; line-height: 1.3; margin: .15rem 0 .3rem; }
.co-meta { font-size: .82rem; 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: 2px; }
.nav a, .nav span.disabled { display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; border-radius: 10px; 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.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-soon { font-size: .76rem; color: #66666d; padding: .9rem .75rem .3rem; }
.side-foot { margin-top: auto; 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; }
.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); }

/* ===== ข้อความแจ้ง ===== */
.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] { width: 18px; height: 18px; 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-item { min-width: 140px; }
.lines .js-account { min-width: 140px; }
.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; }

/* ===== หน้าเข้าสู่ระบบ ===== */
.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; 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; 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: .7rem; padding: .55rem .75rem; border-radius: 10px;
  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 { color: #fff; }
.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: .45rem .75rem .45rem 2.75rem; font-size: .94rem; position: relative; }
.nav .sub::before { content: ""; position: absolute; left: 1.55rem; top: 50%; width: 6px; height: 6px; border-radius: 50%;
  background: #4a4a50; transform: translateY(-50%); }
.nav .sub.active::before { background: var(--black); }
.nav span.sub.disabled { color: #5c5c63; }
@media (max-width: 900px) {
  .nav-group { display: contents; }
  .nav-group summary { display: none; }
  .nav .sub { padding: .45rem .7rem; }
  .nav .sub::before { display: none; }
  .nav span.sub.disabled { display: none; }
}
