:root {
  --bg: #eceff2;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #667282;
  --line: #d3d9e0;
  --line-soft: #e6eaee;
  --brand: #1f4e8c;
  --brand-ink: #ffffff;
  --blue-slip: #d5e5f7;
  --blue-slip-ink: #1b4478;
  --yellow-slip: #f8e9a6;
  --yellow-slip-ink: #6b5400;
  --danger: #a3322b;
  --ok: #1e6b43;
  --r: 5px;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Sarabun', 'Noto Sans Thai', Tahoma, sans-serif; line-height: 1.5;
}
a { color: var(--brand); }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 2px; font-weight: 700; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.r { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
code { background: #f1f3f5; padding: 1px 5px; border-radius: 3px; }
hr { border: 0; border-top: 1px solid var(--line-soft); margin: 18px 0; }

/* ---------- แถบบน ---------- */
.top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1120px; margin: 0 auto; padding: 0 20px; height: 58px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { height: 34px; width: auto; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand b { font-size: 1.02rem; }
.brand small { color: var(--muted); font-size: .76rem; }
.top nav { display: flex; gap: 2px; flex: 1; }
.top nav a, .who a { padding: 6px 12px; text-decoration: none; color: var(--ink); border-radius: var(--r); font-size: .95rem; }
.top nav a:hover, .who a:hover { background: #f0f2f5; }
.top nav a.on, .who a.on { background: #e6edf6; color: var(--brand); font-weight: 600; }
.who { display: flex; align-items: center; gap: 4px; font-size: .92rem; }
.who .out { color: var(--muted); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 90px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- ปุ่ม / ป้าย ---------- */
.btn {
  display: inline-block; padding: 8px 16px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: var(--r); font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none; line-height: 1.3;
}
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { background: #193f73; }
.btn.blue { background: var(--blue-slip); border-color: #aac6e8; color: var(--blue-slip-ink); font-weight: 600; }
.btn.blue:hover { background: #c6dcf3; }
.btn.yellow { background: var(--yellow-slip); border-color: #e2cf7a; color: var(--yellow-slip-ink); font-weight: 600; }
.btn.yellow:hover { background: #f4e08a; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn.ghost:hover { background: #eef2f7; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 10px; font-size: .86rem; }
.btn.block { display: block; width: 100%; text-align: center; padding: 10px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.tag { display: inline-block; padding: 1px 9px; border-radius: 3px; font-size: .8rem; font-weight: 600; vertical-align: middle; border-left: 4px solid; }
.tag.blue { background: var(--blue-slip); color: var(--blue-slip-ink); border-color: #4b86cf; }
.tag.yellow { background: var(--yellow-slip); color: var(--yellow-slip-ink); border-color: #d2a900; }
h1 .tag { margin-left: 10px; font-size: .78rem; }

.notice { padding: 10px 14px; border-radius: var(--r); margin-bottom: 14px; border: 1px solid; font-size: .95rem; }
.notice.ok { background: #e7f3ec; border-color: #b6d9c4; color: var(--ok); }
.notice.err { background: #fbeceb; border-color: #e5b9b6; color: var(--danger); }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-size: .9rem; color: #3b4654; font-weight: 500; }
.lbl { font-size: .9rem; color: #3b4654; font-weight: 500; margin-bottom: 4px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; font-size: 1rem; color: var(--ink);
  background: #fff; border: 1px solid #bcc4cf; border-radius: var(--r);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fb2de; outline-offset: -1px; border-color: var(--brand); }
input[type=radio], input[type=checkbox] { display: inline-block; width: auto; margin: 0 6px 0 0; accent-color: var(--brand); }
.grid { display: grid; gap: 14px 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.grid.tight { margin-top: 14px; align-items: end; }
.span2 { grid-column: span 2; }
label.full { margin-top: 14px; }
.radios { display: flex; gap: 20px; padding: 8px 0; }
.radios label { display: flex; align-items: center; font-size: 1rem; color: var(--ink); }
.buyonly, .hireonly { display: none; }
body[data-kind=buy] .buyonly, body[data-kind=hire] .hireonly { display: inline; }
body[data-kind=buy] .radios.buyonly, body[data-kind=hire] .radios.hireonly { display: flex; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 18px 20px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 480px; }
.card.narrow label { margin-bottom: 12px; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }

/* ประเภทเอกสาร (สลับใบฟ้า/ใบเหลือง) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #fff; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 16px; cursor: pointer; font-size: .95rem; color: var(--ink); }
.seg label:first-child input:checked + span { background: var(--yellow-slip); color: var(--yellow-slip-ink); font-weight: 600; }
.seg label:last-child input:checked + span { background: var(--blue-slip); color: var(--blue-slip-ink); font-weight: 600; }

/* ---------- ใบเสนอราคา ---------- */
.quote .drop {
  display: block; border: 1.5px dashed #9fb1c7; border-radius: var(--r); background: #f7f9fc; padding: 18px; text-align: center;
  color: #3b4654; cursor: pointer;
}
.quote .drop:hover, .quote .drop.over { background: #eaf1fa; border-color: var(--brand); }
.quote .drop input { display: none; }
.files { list-style: none; margin: 12px 0 0; padding: 0; }
.files li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: var(--r); margin-bottom: 6px; flex-wrap: wrap; }
.files li a { font-weight: 500; word-break: break-all; }
.files li .btn:first-of-type { margin-left: auto; }
.files li.busy { opacity: .6; }
#aimsg { margin: 10px 0 0; }

/* ---------- ตารางรายการ ---------- */
.tablewrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; min-width: 860px; }
table.items th { text-align: left; font-size: .82rem; color: var(--muted); font-weight: 600; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.items th.r { text-align: right; }
table.items td { padding: 8px 4px 8px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.items td.n { color: var(--muted); padding-top: 14px; text-align: center; }
table.items input, table.items select, table.items textarea { margin-top: 0; padding: 6px 8px; font-size: .95rem; }
table.items textarea { margin-top: 4px; min-height: 34px; font-size: .88rem; color: #3b4654; background: #fafbfc; }
table.items td.amt { text-align: right; padding-top: 14px; font-variant-numeric: tabular-nums; }
table.items input.r { text-align: right; }
table.items tfoot td { border-bottom: 0; padding-top: 12px; }
table.items .baht { color: var(--ink); background: #f4f6f9; border-radius: var(--r); text-align: center; font-weight: 500; }
.xbtn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.2rem; padding: 4px 8px; margin-top: 4px; border-radius: 4px; }
.xbtn:hover { background: #f6e3e1; color: var(--danger); }

.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px; padding: 12px 20px; margin: 20px -20px 0;
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
}
.grow { flex: 1; }

/* ---------- รายการเอกสาร ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { flex: 1; min-width: 220px; margin: 0; }
.filters select { width: auto; margin: 0; }
table.ledger { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
table.ledger th { text-align: left; font-size: .82rem; color: var(--muted); font-weight: 600; padding: 10px 12px; background: #f6f8fa; border-bottom: 1px solid var(--line); }
table.ledger th.r { text-align: right; }
table.ledger td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.ledger tr:last-child td { border-bottom: 0; }
table.ledger tbody tr:hover { background: #fafbfc; }
.rowlink { font-weight: 600; color: var(--ink); text-decoration: none; }
.rowlink:hover { color: var(--brand); text-decoration: underline; }
.rowacts { white-space: nowrap; text-align: right; }
.rowacts .inline { display: inline; }
.empty { background: #fff; border: 1px dashed var(--line); border-radius: 6px; padding: 40px 20px; text-align: center; }
.pager { display: flex; gap: 4px; margin-top: 14px; justify-content: center; }
.pager a { padding: 4px 11px; border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; background: #fff; color: var(--ink); }
.pager a.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- ผู้ใช้งาน ---------- */
.userrow { display: grid; grid-template-columns: 130px 1.2fr 1fr 1fr 110px 80px 1.1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.userrow:last-child { border-bottom: 0; }
.userrow input, .userrow select { margin: 0; padding: 6px 8px; font-size: .92rem; }
.userrow .uid { display: flex; flex-direction: column; line-height: 1.2; }
.userrow.off { opacity: .55; }
.chk { display: flex; align-items: center; margin: 0; color: var(--ink); }

/* ---------- เข้าสู่ระบบ / ติดตั้ง ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { display: grid; grid-template-columns: 1fr 1fr; width: 100%; max-width: 860px; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.login-side { background: var(--blue-slip); padding: 44px 36px; display: flex; flex-direction: column; justify-content: center; }
.login-emblem { width: 76px; height: auto; margin-bottom: 18px; }
.login-side h1 { font-size: 1.5rem; color: #12345c; }
.login-side p { margin: 4px 0 0; color: #35557d; font-size: .92rem; }
.slips { margin-top: 30px; display: flex; flex-direction: column; gap: 8px; }
.slip { display: block; padding: 9px 14px; border-radius: 3px; font-weight: 700; font-size: .95rem; border-left: 5px solid; }
.slip small { font-weight: 400; margin-left: 8px; }
.slip.blue { background: #f3f8fe; border-color: #4b86cf; color: #1b4478; width: 78%; }
.slip.yellow { background: var(--yellow-slip); border-color: #d2a900; color: var(--yellow-slip-ink); width: 78%; margin-left: 22%; }
.login-form { padding: 44px 36px; }
.login-form h2 { font-size: 1.35rem; margin-bottom: 4px; }
.login-form p { margin: 0 0 18px; }
.login-form label { margin-bottom: 14px; }
.login-form .btn { margin-top: 6px; }
.install { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 32px; width: 100%; max-width: 440px; }
.install label { margin-bottom: 12px; }

@media (max-width: 820px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .login { grid-template-columns: 1fr; }
  .login-side { padding: 26px; }
  .slips { display: none; }
  .top-in { gap: 12px; height: auto; padding: 8px 14px; flex-wrap: wrap; }
  .brand small { display: none; }
  .userrow { grid-template-columns: 1fr 1fr; }
  table.ledger { display: block; overflow-x: auto; }
}

.paste { margin-top: 12px; border: 1px solid var(--line-soft); border-radius: var(--r); padding: 8px 12px; }
.paste summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.paste textarea { margin: 6px 0 8px; font-size: .92rem; }

/* ผู้ลงนาม: ตำแหน่ง | ชื่อ | กลุ่มงาน */
.signers { display: grid; grid-template-columns: 230px 1fr 1fr; gap: 8px 12px; align-items: center; }
.signers input { margin: 0; }
.signers .sh { font-size: .82rem; color: var(--muted); font-weight: 600; }
.signers .sr { font-size: .95rem; font-weight: 500; }
@media (max-width: 820px) { .signers { grid-template-columns: 1fr; } .signers .sh { display: none; } .signers .sr { margin-top: 8px; } }
