:root {
  --bg: #e2eafb; --surface: #fbfcff; --ink: #1b2550; --muted: #55608c; --line: #c8d4f0;
  --side: #cbdcfc; --side-ink: #1e3a8a;
  --accent: #4338ca; --accent-2: #2b8fe8; --accent-soft: #d6dfff; --accent-ink: #fff;
  --ok: #3f7a55; --ok-soft: #dcebdf; --warn: #a8690a; --warn-soft: #fbe7b8; --bad: #b3261e;
  --blue: #7c3aed; --blue-soft: #efe8fe; --amber: #f0b429;
  --shadow: 0 1px 0 #fff inset, 0 6px 18px rgba(50, 70, 150, .10);
  --display: "IBM Plex Sans Thai", "Leelawadee UI", sans-serif;
  --body: "Sarabun", "Leelawadee UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.6; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.3; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.05rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.grow { flex: 1 1 auto; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

/* ค่าฐานของช่องกรอกทุกช่อง (ทับได้ด้วยคลาส) */
:where(input, select, textarea, button) { font: inherit; color: inherit; }
:where(input, select, textarea) { width: 100%; padding: 8px 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
:where(input, select, textarea):disabled { background: var(--bg); color: var(--ink); opacity: 1; }
:where(input, select, textarea, button, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 2px; }
button { padding: 8px 18px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; white-space: nowrap; font-family: var(--display); font-weight: 600; font-size: .95rem; box-shadow: var(--shadow); }
button:hover { border-color: var(--accent-2); }
button.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; color: var(--accent-ink); text-shadow: 0 1px 1px rgba(30, 30, 110, .35); }
button.primary:hover { filter: brightness(.96); }
button:disabled { opacity: .6; cursor: default; }
a { color: var(--accent); }

.card { background: var(--surface); border: 2px solid #fff; border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.login { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.msg { min-height: 1.6em; font-size: .95rem; color: var(--ok); }
.msg.bad { color: var(--bad); }

/* ── โครงหน้า: เมนูซ้าย + เนื้อหา ── */
#app { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
#app.navhide { grid-template-columns: minmax(0, 1fr); }
#app.navhide .side { display: none; }
.side { position: sticky; top: 12px; height: calc(100vh - 24px); margin: 12px 0 12px 12px; padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; background: linear-gradient(180deg, #cbdcfc, #c8c2f5); border-radius: 26px; color: var(--side-ink); box-shadow: 0 6px 18px rgba(60, 80, 160, .15); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 16px; text-decoration: none; color: var(--side-ink); }
.brand .logo { flex: 0 0 auto; width: 54px; height: 54px; border-radius: 18px; object-fit: cover; border: 2px solid #fff; display: grid; place-items: center; background: #fff; color: #fff; font-family: var(--display); font-weight: 700; font-size: 1.2rem; box-shadow: 0 4px 10px rgba(79, 70, 229, .28); }
.brand b { display: block; font-family: var(--display); font-size: 1rem; line-height: 1.25; }
.brand small { display: block; font-size: .8rem; color: #5a6a9a; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav .item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 16px; font-family: var(--display); font-weight: 600; font-size: .98rem; white-space: nowrap; color: var(--side-ink); text-decoration: none; }
.nav .item svg { flex: 0 0 auto; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav a.item:hover { background: rgba(255, 255, 255, .45); }
.nav .item.on { background: var(--surface); box-shadow: 0 4px 12px rgba(60, 80, 160, .18); }
.nav .item.soon { color: #6f7fb0; cursor: default; }
.nav .item.soon em { margin-left: auto; font-style: normal; font-family: var(--body); font-weight: 400; font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, .55); white-space: nowrap; }
.navhead { padding: 12px 12px 4px; font-family: var(--display); font-weight: 700; font-size: .75rem; letter-spacing: .05em; color: #6f7fb0; }
.sidefoot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .6); display: flex; flex-direction: column; gap: 8px; }
.sidefoot #who { font-size: .85rem; color: #46558a; padding: 0 6px; overflow-wrap: anywhere; }
.sidefoot button { width: 100%; }
.scrim { display: none; }

.main { min-width: 0; padding: 12px 20px 28px; display: flex; flex-direction: column; gap: 16px; }
.top { display: flex; align-items: center; gap: 14px; padding: 12px 18px; background: var(--surface); border: 2px solid #fff; border-radius: 22px; box-shadow: var(--shadow); }
.top .burger { padding: 6px 10px; border: 0; background: none; box-shadow: none; font-size: 1.3rem; line-height: 1; }
.top b { display: block; font-family: var(--display); font-size: 1.05rem; line-height: 1.3; }
.top small { display: block; font-size: .82rem; color: var(--muted); }
.page { display: flex; flex-direction: column; gap: 16px; }

/* ── หน้าหลัก: การ์ดเลือกงาน ── */
#app.home, #app.home.navhide { grid-template-columns: minmax(0, 1fr); }
#app.home .side, #app.home .burger, #app.home .scrim { display: none !important; }
#app.home .main { max-width: 1280px; width: 100%; margin: 0 auto; }
.hello { padding: 6px 4px 0; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.app { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 24px 20px 0; text-align: center; text-decoration: none; color: var(--ink); white-space: normal; font-family: var(--body); font-weight: 400; cursor: pointer; transition: transform .12s; }
a.app:hover, button.app:hover { transform: translateY(-2px); border-color: #fff; box-shadow: 0 1px 0 #fff inset, 0 10px 24px rgba(50, 70, 150, .16); }
.app b { font-family: var(--display); font-size: 1.1rem; margin-top: 12px; }
.app small { font-size: .85rem; color: var(--muted); min-height: 1.6em; }
.app .go { align-self: stretch; margin-top: 14px; padding: 12px 0; border-top: 1px solid var(--line); font-family: var(--display); font-weight: 600; font-size: .95rem; color: var(--accent); }
.appico { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; color: #fff; box-shadow: 0 6px 14px rgba(50, 70, 150, .22); }
.appico svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.appico.c1 { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.appico.c2 { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.appico.c3 { background: linear-gradient(135deg, #aab4d4, #7a86ad); }
.appico.c4 { background: linear-gradient(135deg, #f7cf5a, #e9a11a); }
.app.soon { cursor: default; opacity: .7; }
.app.soon .go { color: var(--muted); }

.hero { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; background: linear-gradient(120deg, #e3edff, var(--surface) 60%); }
.hero .txt { flex: 1 1 320px; min-width: 0; }
.tag { display: inline-block; padding: 2px 12px; border-radius: 999px; background: var(--accent-soft); color: #1e40af; font-family: var(--display); font-weight: 700; font-size: .78rem; letter-spacing: .04em; margin-bottom: 6px; }
.hero .filters { display: flex; flex-direction: column; gap: 8px; flex: 0 1 340px; }
.hero .filters .row { display: flex; gap: 8px; align-items: center; }
.hero .filters label { margin: 0; white-space: nowrap; }
.hero .filters :where(input, select) { border-radius: 999px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { padding: 16px 18px; border-left: 4px solid var(--c); }
.stat span { display: block; font-size: .9rem; color: var(--muted); }
.stat b { display: block; font-family: var(--display); font-size: 1.7rem; line-height: 1.4; color: var(--c); font-variant-numeric: tabular-nums; }
.stat small { display: block; font-size: .8rem; color: var(--muted); }
.stat.s1 { --c: var(--ok); } .stat.s2 { --c: var(--accent); } .stat.s3 { --c: #b8851f; } .stat.s4 { --c: var(--blue); background: linear-gradient(120deg, var(--surface), var(--blue-soft)); }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bar label { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: 1rem; }
.check input { width: auto; accent-color: var(--accent); }
.cardhead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cardhead h3 { color: #1e40af; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--display); font-size: .88rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .6); }
td a { font-weight: 600; text-decoration: none; }
#ovTable td:nth-child(3) { min-width: 240px; }
td a:hover { text-decoration: underline; }
.num { text-align: right; white-space: nowrap; }
.mono { white-space: nowrap; }
td.warn { color: var(--warn); font-weight: 600; }
td.ok { color: var(--ok); }
td.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.pill { display: inline-block; padding: 1px 12px; border-radius: 999px; font-family: var(--display); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: #2c5c3e; }
.pill.warn { background: var(--warn-soft); color: #7a4b00; }

/* ── ตารางกรอกเงินได้รายเดือน ── */
.cardhead label { margin: 0; white-space: nowrap; }
select.auto { width: auto; border-radius: 999px; }
.paygrid th, .paygrid td { padding: 6px 6px; vertical-align: middle; }
.paygrid th:not(:nth-child(2)), .paygrid td:not(:nth-child(2)) { text-align: right; white-space: nowrap; }
.paygrid .stick { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 200px; white-space: nowrap; }
.paygrid .carry { background: rgba(227, 236, 245, .55); }
.paygrid .tot { font-weight: 600; }
.paygrid tfoot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0; }
.paygrid input.cell { width: 104px; padding: 5px 8px; border-radius: 8px; text-align: right; font-variant-numeric: tabular-nums; }
.paygrid input.cell.dirty { background: var(--warn-soft); }
.paygrid input.cell.bad { border-color: var(--bad); background: #fde4e1; }
.hint { font-size: .88rem; margin-top: 8px; }

/* ── หน้านำเข้า ── */
#impTable td, #batTable td { vertical-align: middle; }
#impTable td.check input { width: 18px; height: 18px; }
#impTable select { min-width: 220px; padding: 5px 10px; border-radius: 10px; }
#impTable tr.dim td { color: var(--muted); }
#impTable td:last-child { min-width: 260px; font-size: .9rem; }
#impTable td:last-child .muted { font-size: .85rem; }
.hero .filters input[type=file] { padding: 6px 10px; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.grid .wide { grid-column: span 2; }
.grid .full { grid-column: 1 / -1; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
dialog { border: 2px solid #fff; border-radius: 24px; padding: 22px; width: min(680px, calc(100vw - 32px)); color: var(--ink); background: var(--surface); box-shadow: 0 20px 50px rgba(30, 40, 90, .3); }
dialog::backdrop { background: rgba(23, 37, 84, .45); }

@media (max-width: 1000px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  #app, #app.navhide { grid-template-columns: minmax(0, 1fr); }
  .side, #app.navhide .side { display: none; position: fixed; z-index: 20; top: 0; left: 0; height: 100vh; width: 264px; margin: 0; border-radius: 0 26px 26px 0; }
  #app.navshow .side { display: flex; }
  #app.navshow .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(23, 37, 84, .4); }
  .main { padding: 10px 16px 24px; }
}
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .grid .wide { grid-column: auto; }
  .stats { gap: 10px; }
  .stat b { font-size: 1.35rem; }
}

/* ── 50 ทวิ · ภ.ง.ด.1ก ── */
.docopts { display: flex; gap: 14px 28px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.docopts input[type=date] { width: auto; border-radius: 999px; }
.warnlist { margin: 0 0 12px; padding: 10px 14px 10px 32px; border-radius: 16px; background: var(--warn-soft); color: #7a4b00; font-size: .95rem; }
.warnlist:empty { display: none; }
#docTable tfoot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--accent-soft); }
tr.rowlink button { padding: 4px 14px; white-space: nowrap; }

/* ── แท็บในหน้านำเข้า + ตารางไฟล์รายเดือน ── */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs button { font-family: var(--display); font-weight: 600; }
.tabs button.on { background: var(--surface); border-color: var(--accent); color: var(--accent); box-shadow: 0 4px 12px rgba(60, 80, 160, .14); }
input.auto { width: auto; }
#imTable td { vertical-align: middle; }
#imTable td.check input { width: 18px; height: 18px; }
#imTable tr.dim td { color: var(--muted); }
#imTable td:last-child { min-width: 300px; font-size: .9rem; }
#imTable td:last-child .muted { font-size: .85rem; }
#imTable td:last-child .bad { color: var(--bad); }

/* วิธีใช้ไฟล์ยื่นออนไลน์ */
.rdhelp { margin-top: 12px; }
.rdhelp summary { cursor: pointer; font-weight: 600; }
.rdhelp ol { margin: 8px 0; padding-left: 22px; line-height: 1.7; }

/* รูปลายเซ็น/ตราประทับในข้อมูลบริษัท */
.imgslot .imgbox { height: 110px; border: 1px dashed #c9ced6; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin: 4px 0 8px; background: repeating-conic-gradient(#f3f4f6 0% 25%, #fff 0% 50%) 0 0 / 16px 16px; }
.imgslot .imgbox img { max-width: 92%; max-height: 96px; }
.imgslot input[type=file] { max-width: 220px; }

/* โลโก้ */
.loginlogo { display: block; width: 210px; height: 210px; margin: 0 auto 4px; border-radius: 28px; }
.login h1 { text-align: center; color: #1e3a8a; }
.hello { display: flex; align-items: center; gap: 16px; }
.hello img { width: 92px; height: 92px; border-radius: 26px; border: 3px solid #fff; box-shadow: var(--shadow); }
h2 { color: #1e3a8a; }

/* หน้าบริษัท: สรุปรายเดือน + รายคนของเดือน */
.pmstats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 14px; }
.linkbtn { padding: 2px 4px; border: 0; background: none; box-shadow: none; color: var(--accent); text-decoration: underline; font-weight: 600; font-size: 1rem; }
.linkbtn:hover { color: var(--blue); }
#pmTable td, #pmTable th { padding: 9px 10px; }
#pmTable .carryrow td { background: rgba(227, 236, 245, .55); }
.paygrid .sumcol { background: var(--accent-soft); font-weight: 600; }
#payMonthBox .cardhead, #payYearBox .cardhead { margin-bottom: 8px; }
@media (max-width: 720px) { .pmstats { grid-template-columns: 1fr; } }

/* การ์ดลายเซ็นและตราประทับ: 2 ช่องเท่ากัน */
.cardhead .sub { font-size: .88rem; margin-top: 2px; }
.imgpair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.imgpair .imgslot b { display: block; font-family: var(--display); margin-bottom: 6px; }
.imgpair .imgslot .imgbox { height: 180px; border-radius: 16px; margin: 0 0 10px; }
.imgpair .imgslot .imgbox img { max-width: 88%; max-height: 156px; }
@media (max-width: 720px) { .imgpair { grid-template-columns: 1fr; } }
.imgpair .imgslot input[type=file] { max-width: none; width: auto; flex: 1 1 320px; }
.imgpair .imgslot .actions { flex-wrap: wrap; }
