/* ออกแบบสำหรับมือถือเป็นหลัก — ปุ่มใหญ่ กดง่าย ใช้มือเดียวได้ */
:root {
  --navy: #1F3864;
  --navy-soft: #BDD6EE;
  --red: #C0392B;
  --bg: #f2f4f7;
  --line: #dfe3e8;
  --muted: #6b7280;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* สิ่งที่สคริปต์สั่งซ่อน (hidden) ต้องหายจริง แม้กฎด้านล่างจะตั้ง display ไว้
   (เคยทำให้ปุ่ม "บันทึกทับใบเดิม" และแถว "หัก ณ ที่จ่าย" โผล่ทั้งที่ซ่อนอยู่) */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  font-family: 'Sarabun', -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  /* ภาษาไทยมีสระบนและวรรณยุกต์ซ้อนกันได้ถึง 2 ชั้น (เช่น ที่ ปุ๋ย ฟู้ดส์)
     ค่าปริยายของเบราว์เซอร์ (~1.2) เตี้ยเกินไป สระจะโดนตัด
     1.45 ให้ที่พอสำหรับทั้งสระบนและสระล่าง */
  line-height: 1.45;
  color: #111;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* หัวเว็บ */
.hd {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: 14px 16px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
}
.hd-title { font-size: 18px; font-weight: 700; }
.hd-user { font-size: 13px; opacity: .85; }
/* ปุ่มเล็กมุมขวาของแถบหัว เช่น ออกจากระบบ */
.hd-btn {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 9px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.hd-btn:active { background: rgba(255,255,255,.28); }

.wrap { padding: 12px; max-width: 640px; margin: 0 auto; }

.card {
  background: #fff; border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-hd {
  font-weight: 700; font-size: 15px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

.lbl {
  display: block; font-size: 13px; color: var(--muted);
  margin: 10px 0 5px; font-weight: 500;
}
.lbl:first-child { margin-top: 0; }

input[type=text], input[type=tel], input[type=date], input[type=email],
input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; /* 16px กัน iOS ซูมอัตโนมัติตอนกดพิมพ์ */
  font-family: inherit; background: #fff; color: #111;
}
textarea { resize: vertical; }

/* ช่องวันที่ + ช่องเลือก (เช่น ภาษา)
   บน iPhone ช่องพวกนี้ใช้หน้าตาของเครื่องเอง ไม่ฟังความกว้างที่ตั้งไว้
   ช่องวันที่จึงยื่นไปชนช่องข้าง ๆ ในแถว 2 ช่อง และสูงไม่เท่าช่องพิมพ์อื่น
   ปิดหน้าตาของเครื่อง แล้วกำหนดความสูงให้เท่าช่องพิมพ์ปกติ */
input[type=date], select {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%;
  height: 47px;   /* = ช่องพิมพ์ปกติ (ขอบบนล่าง 12+12 + ตัวอักษร + เส้นกรอบ) */
}
/* iPhone จัดวันที่ไว้กลางช่อง — ให้ชิดซ้ายเหมือนช่องอื่น */
input[type=date]::-webkit-date-and-time-value { text-align: left; margin: 0; }
/* ปิดหน้าตาเดิมแล้วลูกศรของช่องเลือกหายไป — วาดลูกศรเอง */
select {
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(31,56,100,.12);
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* ให้ช่องในแถวหดตามคอลัมน์ได้ ไม่ดันกันล้น (ช่องวันที่บน iPhone) */
.row2 > * { min-width: 0; }
.row2[hidden] { display: none; }
/* ป้ายในกล่อง row2 เป็นลูกตัวแรก จึงไม่มีระยะบน — ใช้คลาสนี้เว้นห่างจากช่องด้านบน */
.row2.gap-top { margin-top: 10px; }

/* ปุ่มเลือกประเภทเอกสาร */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
/* แถวปุ่มกรองในหน้าสรุปงาน เว้นห่างจากช่องค้นหาเพิ่ม */
#filters.chips { margin-top: 10px; margin-bottom: 0; }
.chip {
  padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  font-size: 14px; font-family: inherit; font-weight: 500;
  cursor: pointer; color: #333;
}
.chip.on {
  background: var(--navy); border-color: var(--navy);
  color: #fff; font-weight: 600;
}
/* หน้างานทั้งหมด: ปุ่มกรอง "เสร็จ" กับ "ทั้งหมด" พื้นเทาบาง ๆ แยกจากปุ่มขั้นของงาน (ตอนเลือกอยู่เป็นสีน้ำเงินเหมือนปุ่มอื่น) */
.chip.soft:not(.on) { background: #f7f7f7; }
/* "ค้าง" ตอนไม่ได้เลือก = ขอบและตัวหนังสือน้ำเงินเข้ม · "ทั้งหมด" ตอนไม่ได้เลือก = ขอบดำ */
.chip.chip-navy:not(.on) { border-color: var(--navy); color: var(--navy); }
.chip.chip-edge:not(.on) { border-color: #000; }

/* รายการบริการ */
.item {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px 12px; margin-bottom: 10px; background: #fbfcfd;
}
/* แถวหัว: เลขลำดับกับปุ่มลบอยู่บรรทัดเดียวกัน มีพื้นที่ของตัวเอง */
.item-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.item .no {
  background: var(--navy-soft); color: var(--navy);
  font-size: 12px; font-weight: 700;
  padding: 3px 11px; border-radius: 999px;
}
.item .del {
  background: none; border: 0; color: var(--red);
  font-size: 18px; cursor: pointer; padding: 2px 4px; line-height: 1;
}
/* หมายเหตุ 1 แถว + ปุ่มเลือกสีเล็ก ๆ ท้ายช่อง (กดซ้ำ = กลับเป็นดำ) */
.item .note-row { display: flex; align-items: center; gap: 6px; }
.item .note-row input { flex: 1; min-width: 0; }
.item .c-tg {
  flex: 0 0 auto; width: 30px; height: 30px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.item .c-tg::before { content: ''; width: 14px; height: 14px; border-radius: 50%; }
.item .c-tg.red::before  { background: #C0392B; }
.item .c-tg.blue::before { background: #2F5496; }
.item .c-tg.on { border: 2px solid #111; }
/* "ยอดเงิน" [ก่อน VAT | รวม VAT] [ช่องกรอก] อยู่บรรทัดเดียวกัน
   ปุ่ม VAT เล็กเท่าที่ยังกดง่าย + ระยะห่างแคบ ช่องกรอกจึงกว้างพอให้เห็นยอดหลักล้านครบ
   (วัดแล้ว: จอกว้าง 360px ช่องกรอกยังใส่ 9,999,999.99 ได้ทั้งตัว) */
.item .amt-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
/* ไม่คิด VAT ทั้งใบ (ไม่มีปุ่ม) — คำว่ายอดเงินห่างช่องกรอก 16px เหมือนเดิม */
.item .amt-row.no-vt { gap: 16px; }
.item .amt-row .lbl { margin: 0; flex: 0 0 auto; white-space: nowrap; }
.item .amt-row input { flex: 1; min-width: 0; text-align: right; padding-left: 8px; padding-right: 8px; }
.item .vt-chips {
  flex: 0 0 auto; display: inline-flex;
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff;
}
.item .vt {
  padding: 4px 7px; border: 0; background: none; cursor: pointer; line-height: 1.4;
  font-family: inherit; font-size: 11.5px; font-weight: 600; color: #555; white-space: nowrap;
}
.item .vt + .vt { border-left: 1px solid var(--line); }
.item .vt.on { background: var(--navy); color: #fff; }
/* กรอกแบบรวม VAT — บอกใต้ช่องว่าบนเอกสารจะเป็นยอดเท่าไหร่ */
.item .vt-hint {
  margin-top: 6px; text-align: right;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.item .vt-hint:empty { display: none; }

.add {
  width: 100%; padding: 13px;
  border: 1.5px dashed var(--navy); border-radius: 10px;
  background: #fff; color: var(--navy);
  font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer;
}

.check { display: flex; align-items: center; gap: 10px; font-size: 15px; padding: 4px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }

/* กล่องสรุปยอด + ปุ่ม อยู่ท้ายหน้า (ไม่ลอยค้างอีกแล้ว) */
.summary { padding: 16px 14px; }
.bar-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 15px; padding: 3px 0;
}
.bar-row.small { font-size: 13.5px; color: var(--muted); }
.bar-row.net {
  font-size: 19px; font-weight: 700; color: var(--navy);
  margin-top: 6px; padding-top: 9px; border-top: 1px solid var(--line);
}
.bar-row b { font-variant-numeric: tabular-nums; }

.go {
  display: block; width: 100%; margin-top: 14px; padding: 16px;
  border: 0; border-radius: 12px;
  background: var(--navy); color: #fff;
  font-size: 17px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.go.alt {
  margin-top: 9px; background: #fff;
  color: var(--navy); border: 1px solid var(--navy);
}
/* ปุ่มที่ทำแล้วย้อนกลับไม่ได้ เช่น ล้างข้อมูลทั้งหมด */
.go.danger { background: var(--red); }
.go:disabled { opacity: .5; }

/* อยู่เหนือแผ่นป๊อปอัป (70) และเมนูหลังบ้าน (90) — ข้อความแจ้ง/error ต้องไม่ถูกบัง */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%); z-index: 95;
  background: #222; color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; max-width: 88vw; text-align: center;
}
.toast.err { background: var(--red); }

/* จำนวนรายการ + ข้อความเตือนเมื่อใกล้ครบ */
.count { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.count.full { color: var(--red); font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 7px; text-align: center; }
.hint.warn { color: var(--red); }

/* เงื่อนไขแต่ละข้อ พร้อมปุ่มเลือกสีแดง */
.term {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.term input[type=text] { flex: 1; }
.term .red-tg {
  flex: 0 0 auto; width: 38px; height: 44px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer; font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.term .red-tg.on { background: #ffe9e9; border-color: var(--red); }
.term .del {
  flex: 0 0 auto; width: 36px; height: 44px;
  border: 0; background: none; color: var(--red);
  font-size: 19px; cursor: pointer;
}

/* แถบบอกว่ากำลังแก้ไขเอกสารใบไหน */
.editbar {
  background: #fff4d6; border: 1px solid #e8cf94;
  border-radius: 10px; padding: 11px 13px; margin-bottom: 12px;
  font-size: 13.5px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.editbar a { color: var(--navy); font-weight: 600; text-decoration: none; white-space: nowrap; }

/* แถวสำนักงานใหญ่ / สาขา — ปุ่มอยู่ซ้าย ช่องกรอกเลขสาขาอยู่ขวา
   เว้นด้านบนให้ห่างช่องชื่อลูกค้า และด้านล่างให้ชิดช่องที่อยู่ */
/* มี 3 ปุ่ม (ไม่มี / สำนักงานใหญ่ / สาขา) — จอแคบ ช่องเลขสาขาจะลงบรรทัดใหม่เอง ไม่ถูกบีบจนพิมพ์ไม่ได้ */
.branch-row {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 0; flex-wrap: wrap;
}
.chips.branch { margin: 0; flex: 0 0 auto; }
.branch-row .branch-no {
  flex: 1 1 120px; min-width: 0;
  padding: 10px 12px; font-size: 15px;
}

/* ช่องเลขที่เอกสาร — ระบบเติมเลขถัดไปให้เป็นค่าเริ่มต้น แก้ทับได้ */
.field-hint {
  font-size: 12.5px; color: var(--muted);
  margin: 3px 0 9px; min-height: 1em; line-height: 1.4;
}
/* ข้อความใต้แถวสาขา — ยุบหายไปเลยตอนไม่มีข้อความ ไม่ให้ดันช่องที่อยู่ห่างเกินไป */
#branchHint { margin: 5px 0 0; min-height: 0; }
#branchHint:empty { display: none; }

/* ===== หน้าสรุปงาน (dashboard) ===== */

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.stat {
  background: #fff; border-radius: 12px; padding: 11px 4px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat .n { font-size: 20px; font-weight: 700; color: #333; line-height: 1.2; }
.stat .t { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.stat.blue  .n { color: #2F5496; }
.stat.amber .n { color: #B8860B; }
.stat.orange .n { color: #B5521E; }
.stat.green .n { color: #1E7B34; }
.stat.brown .n { color: #B07D2E; }
.stats.c4 { grid-template-columns: repeat(4, 1fr); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14.5px; line-height: 1.6; }

/* ปุ่มลอยมุมล่างขวา */
.fab {
  position: fixed; right: 16px; z-index: 40;
  bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--navy); color: #fff;
  padding: 15px 22px; border-radius: 999px;
  font-size: 15.5px; font-weight: 700; text-decoration: none;
  box-shadow: 0 4px 14px rgba(31,56,100,.35);
}

/* ปุ่มย้อนกลับบนแถบหัวทุกหน้า — กดง่ายบนมือถือ (พื้นที่กดกว้างพอ) */
.hd-title .back {
  color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; margin-right: 4px; margin-left: -6px;
  border-radius: 8px; font-size: 22px; line-height: 1;
  background: none; border: 0; font-family: inherit; cursor: pointer;
}
.hd-title .back:active { background: rgba(255,255,255,.18); }
/* หัวเรื่องยาวเกินให้ตัดท้าย ไม่ดันปุ่มตกบรรทัด */
.hd-title {
  display: flex; align-items: center; min-width: 0;
  /* ความสูงเท่าปุ่มย้อนกลับ เพื่อให้แถบหัวสูงเท่ากันทุกหน้า
     ไม่ว่าหน้านั้นจะมีปุ่มย้อนกลับหรือไม่ */
  min-height: 32px;
}
.hd-title .t {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ===== ตารางงาน: กล่องเดียว แบ่งด้วยเส้นคั่น ===== */
.table {
  background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.row {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 0; border-bottom: 1px solid var(--line);
  padding: 11px 13px; font-family: inherit; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: #f6f8fb; }
.row:focus-visible { outline: 2px solid var(--navy-soft); outline-offset: -2px; }
/* ชื่อลูกค้าในหน้างานทั้งหมด ลากเลือกเพื่อคัดลอกได้ + ปุ่มคัดลอกเล็ก ๆ ติดท้ายชื่อ */
.row .row-cust { -webkit-user-select: text; user-select: text; }
/* ชื่อ + ปุ่มคัดลอก เป็นกลุ่มเดียวกัน กินที่ที่เหลือ (ดันสถานะไปชิดขวา) ชื่อยาวตัด … แต่ปุ่มยังอยู่ท้ายชื่อเสมอ */
.row-name { flex: 1; min-width: 0; display: flex; align-items: center; }
.row-name .row-cust { flex: 0 1 auto; }
/* ปุ่มกว้าง 24px ไอคอน 14px อยู่กลาง (รูปไอคอนตัดขอบว่างออกแล้ว) = ไอคอนห่างจากชื่อ 5px พอดี */
.cp-btn {
  flex: 0 0 auto; width: 24px; height: 28px; margin: -3px 0; padding: 0;
  border: 0; border-radius: 7px; cursor: pointer; opacity: .55;
  background: no-repeat center / 14px 14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='2 2 20 20' fill='none' stroke='%231F3864' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1'/%3E%3C/svg%3E");
}
.cp-btn:hover, .cp-btn:active { opacity: 1; background-color: #eef2f9; }

/* ทั้ง 3 บรรทัดเว้นระยะเท่ากัน (5px) และจัดกึ่งกลางแนวตั้งเหมือนกัน */
.row-1 { display: flex; align-items: center; gap: 8px; }
.row-cust {
  flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; color: #111;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  /* ตัวหนา + สระบน ต้องการที่มากกว่าปกติเล็กน้อย
     วัดแล้ว: ตัวอักษรไทยที่มีสระครบสูง 24px ที่ font-size 14.5px */
  line-height: 1.6; padding-block: 1px;
}
.row-2 {
  display: flex; align-items: center; gap: 7px;
  margin-top: 5px; font-size: 11.5px; color: var(--muted);
}
/* หน้างานทั้งหมด บรรทัด 2: เลขที่เอกสารทุกใบของงาน (ซ้าย ยาวก็ขึ้นบรรทัดใหม่) + ยอดเงิน (ขวา ตรงบรรทัดแรก) */
.row-2.nos { align-items: baseline; }
.row-no { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; line-height: 1.6; }
.row-no .dn { white-space: nowrap; }
/* ยอดเงินชิดขวาสุดของบรรทัดเดียวกับวันที่ */
.row-amt {
  margin-left: auto; font-size: 14px; font-weight: 700;
  color: var(--navy); font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* บรรทัด 3: tag บริการ (ซ้าย) + วันที่ (ขวา ใต้ยอดเงินพอดี) */
.row-3 {
  display: flex; align-items: center; gap: 8px;
  margin-top: 5px; font-size: 11.5px; color: var(--muted);
}
.row-svc {
  flex: 1; min-width: 0; font-size: 12px; color: #555;
  display: flex; flex-wrap: wrap; gap: 5px; overflow: hidden;
  align-items: center;
}
.row-date { margin-left: auto; white-space: nowrap; }
/* หน้างานทั้งหมด: tag บริการหลายบรรทัด — วันที่อยู่บรรทัดสุดท้าย ตรงกับ tag แถวล่างสุด
   (วันที่สูงเท่า tag 1 แถว แล้วชิดล่าง · ไม่มี tag = ตรงกับบรรทัดข้อความธรรมดา) */
.row-3.tags { align-items: flex-end; }
.row-3.tags .row-date { line-height: 1.5; padding: 3px 0; }
.row-3.tags .row-svc.plain + .row-date { line-height: 1.6; padding: 0; }
/* ถ้าไม่มีบริการที่เลือก จะแสดงเป็นข้อความธรรมดาแทน */
.row-svc.plain {
  display: block; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.6;   /* กันสระไทยโดนตัด เพราะช่องนี้มี overflow: hidden */
}
/* tag บอกว่าเป็นบริการอะไร */
/* ป้ายทั้งหมด: เว้นบน-ล่างให้สระไทยมีที่อยู่ ไม่ชนขอบป้าย */
.stag {
  background: var(--navy); color: #fff;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 8px; border-radius: 5px; white-space: nowrap;
  line-height: 1.5;
}
.tag {
  background: var(--navy-soft); color: var(--navy); font-weight: 600;
  padding: 3px 6px; border-radius: 5px; font-size: 11px; white-space: nowrap;
  line-height: 1.5;
}
/* หน้างานทั้งหมด: แท็กบริการ (.stag) = ตัวขาวพื้นน้ำเงิน */
.badge {
  flex: 0 0 auto; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  line-height: 1.5;
}
.badge.blue  { background: #E4ECF9; color: #2F5496; }
.badge.amber { background: #FDF0D5; color: #8A6400; }
.badge.orange{ background: #FFE8D9; color: #B5521E; }
.badge.green { background: #E1F3E6; color: #1E7B34; }
.badge.grey  { background: #ECEEF1; color: #555; }

/* ===== แผ่นรายละเอียด กางขึ้นจากข้างล่าง ===== */
/* สำคัญ: display:flex จะลบล้าง attribute hidden ทำให้แผ่นใส ๆ บังทั้งจอ
   จนกดปุ่มอะไรไม่ได้ ต้องสั่งซ่อนให้ชัดเจนเมื่อมี hidden */
.sheet-bg[hidden] { display: none; }
.sheet-bg {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0);
  display: flex; align-items: flex-end; justify-content: center;
  transition: background .2s ease;
}
.sheet-bg.show { background: rgba(0,0,0,.45); }
.sheet-panel {
  position: relative; background: #fff;
  width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0;
  max-height: 88vh; overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease;
}
.sheet-bg.show .sheet-panel { transform: translateY(0); }

/* แผ่นเลือกบริการ วางกลางจอ เว้นที่บน-ล่าง */
.sheet-bg.center { align-items: center; padding: 24px 12px; }
.sheet-bg.center .sheet-panel {
  border-radius: 16px; max-height: 100%;
  transform: translateY(16px) scale(.98); opacity: 0;
  transition: transform .2s ease, opacity .2s ease;
}
.sheet-bg.center.show .sheet-panel { transform: none; opacity: 1; }
.sheet-grip {
  width: 40px; height: 4px; border-radius: 2px;
  background: #d3d8de; margin: 4px auto 10px;
}
.sheet-x {
  position: absolute; top: 10px; right: 12px;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: #f0f2f5; color: #444; font-size: 15px; cursor: pointer;
}

/* เดิมเว้นขวา 40px ไว้หลบปุ่มปิดของแผ่นป๊อปอัป ตอนนี้เป็นหน้าเต็มแล้วจึงไม่ต้องเว้น
   ป้ายสถานะจะได้ห่างจากขอบบนและขอบขวาเท่ากันพอดี */
.sh-top { display: flex; align-items: flex-start; gap: 10px; }
.sh-cust { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; line-height: 1.4; }
.sh-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 7px; font-size: 12.5px; color: var(--muted);
}

.sh-info { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.kv { display: flex; gap: 10px; font-size: 13.5px; padding: 3px 0; line-height: 1.5; }
.kv .k { flex: 0 0 96px; color: var(--muted); }
.kv .v { flex: 1; color: #222; }

.sh-label {
  margin-top: 14px; font-weight: 700; font-size: 14px;
  padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.sv { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f0f2f5; }
.sv-no {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  background: var(--navy-soft); color: var(--navy);
  font-size: 12px; font-weight: 700; text-align: center; line-height: 22px;
}
.sv-tx { flex: 1; min-width: 0; }
.sv-desc { font-size: 13.5px; line-height: 1.5; color: #111; }
.sv-note { font-size: 12px; color: var(--red); margin-top: 2px; line-height: 1.4; }
.sv-amt {
  flex: 0 0 auto; font-size: 13.5px; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.sh-sum { margin-top: 12px; }
.sm {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13.5px; padding: 3px 0; color: #444;
}
.sm b { font-variant-numeric: tabular-nums; }
.sm.net {
  font-size: 18px; font-weight: 700; color: var(--navy);
  margin-top: 6px; padding-top: 9px; border-top: 1px solid var(--line);
}

/* ปุ่มการทำงาน (ใช้ทั้งในแผ่นรายละเอียด) */
.act {
  padding: 9px 13px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: #333;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  text-decoration: none; cursor: pointer; display: inline-block;
}
.act.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.act.ok { background: #E1F3E6; border-color: #A9D8B8; color: #1E7B34; }
/* ปุ่มที่กดไม่ได้ (เช่น ไม่มีเอกสารต้นทางให้เปิด) */
.act.off { background: #f3f4f6; border-color: #e5e7eb; color: var(--muted); cursor: not-allowed; pointer-events: none; }

.sh-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.sh-acts .act {
  flex: 1 1 calc(50% - 4px); padding: 13px 10px;
  display: flex; align-items: center; justify-content: center; text-align: center;
}

/* ===== แผ่นเลือกบริการ ===== */
.pick {
  width: 100%; padding: 11px; margin-bottom: 4px;
  border: 1px solid var(--navy); border-radius: 9px;
  background: #fff; color: var(--navy);
  font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.pick:active { background: #eef2f9; }
.pick.has { border-color: var(--line); background: #f0f4fa; color: #111; text-align: left; }
.pick.has .pick-tx::before { content: 'บริการ: '; color: var(--muted); font-weight: 500; }

.svc-list { margin-top: 12px; }
/* หัวข้อหมวด — กดเพื่อกาง/ยุบ */
.svc-group {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left;
  background: #f5f7fa; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 13px; margin-bottom: 7px;
  font-family: inherit; font-size: 14.5px; font-weight: 700; color: #222;
  cursor: pointer;
}
.svc-group::after {
  content: '▾'; color: var(--muted); font-size: 12px;
  transition: transform .15s ease; order: 3;
}
.svc-group.open { background: var(--navy); color: #fff; border-color: var(--navy); }
.svc-group.open::after { transform: rotate(180deg); color: #fff; }
.svc-cnt {
  margin-left: auto; font-size: 12px; font-weight: 600;
  color: var(--muted); background: #fff; border-radius: 999px; padding: 1px 8px;
}
.svc-group.open .svc-cnt { color: var(--navy); }
.svc-empty { text-align: center; color: var(--muted); padding: 20px; font-size: 13.5px; }

/* ฟอร์มเพิ่มบริการใหม่ */
.svc-add { padding: 4px 0; }
.svc-add-hd { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.svc-add-btns { display: flex; gap: 8px; margin-top: 14px; }
.svc-add-btns .act { flex: 1; text-align: center; padding: 12px; }
.svc {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; margin-bottom: 7px;
  font-family: inherit; cursor: pointer;
}
.svc:active { background: #f0f4fa; }
.svc-n { font-size: 14.5px; font-weight: 600; color: #111; }
/* เอกสารภาษาอังกฤษ: ชื่ออังกฤษของบริการใต้ชื่อไทย */
.svc-en { font-size: 13px; font-weight: 600; color: var(--navy); margin-top: 1px; }
.svc-d { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.svc.other {
  border-style: dashed; border-color: var(--navy); color: var(--navy);
  font-size: 14.5px; font-weight: 600; text-align: center; margin-top: 12px;
}

/* ===== หน้าหลังบ้าน ===== */
.adm {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid #f0f2f5;
}
.adm-tx { flex: 1; min-width: 0; }
.adm-n { font-size: 14.5px; font-weight: 600; color: #111; }
/* รายการบริการ: ชื่อ/รายละเอียดภาษาอังกฤษ (ว่าง = ไม่แสดง) */
.adm-en { font-size: 13px; font-weight: 600; color: var(--navy); margin-top: 1px; }
.adm-en:empty, .adm-den:empty { display: none; }
.adm-den { color: #2F5496; }
.adm-d { font-size: 12.5px; color: #555; margin-top: 2px; line-height: 1.45; }
.adm-u { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.adm-x {
  flex: 0 0 auto; width: 32px; height: 32px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--red); font-size: 13px; cursor: pointer;
}

/* ชื่อบริการที่เลือก กำกับไว้เมื่อรายละเอียดถูกแก้จนต่างออกไป */
.sv-svc {
  display: inline-block; font-size: 11px; font-weight: 600;
  color: var(--navy); background: var(--navy-soft);
  padding: 1px 7px; border-radius: 5px; margin-bottom: 3px;
}

.svc-title { font-size: 16px; font-weight: 700; margin: 2px 0 10px; padding-right: 40px; }

/* ===== หน้าต่างยืนยันก่อนบันทึกเอกสาร ===== */
.sheet-panel.cf { max-width: 440px; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.cf-title { font-size: 17px; font-weight: 700; color: #111; margin-bottom: 10px; }
.cf-rows { border-top: 1px solid var(--line); }
.cf-row {
  display: flex; gap: 12px; justify-content: space-between; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid #f0f2f5; font-size: 14px;
}
.cf-row .k { flex: 0 0 auto; color: var(--muted); }
.cf-row .v { text-align: right; color: #111; word-break: break-word; }
.cf-row.strong .v { font-size: 17px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.cf-notes:empty { display: none; }
.cf-note {
  margin-top: 10px; padding: 9px 11px; border-radius: 9px;
  background: #EAF1FB; color: #1F3864; font-size: 13px; line-height: 1.5;
}
.cf-note.warn { background: #FDF0D5; color: #8A6400; font-weight: 600; }
.sheet-panel.cf .go { margin-top: 14px; }
.sheet-panel.cf .go.alt { margin-top: 8px; }

/* ===== การรับเงินเป็นงวด ===== */
.sm.paid   { color: #1E7B34; }
.sm.remain { color: #B8860B; font-weight: 600; }
.sm.done   { color: #1E7B34; font-weight: 600; }

.sh-pay { margin-top: 4px; }
.pay-load, .pay-none, .pay-full {
  font-size: 13px; color: var(--muted); padding: 10px 0; text-align: center;
}
.pay-full { color: #1E7B34; font-weight: 600; }
.pay-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0; border-bottom: 1px solid #f0f2f5; font-size: 13.5px;
}
.pay-n {
  flex: 0 0 auto; font-size: 11.5px; font-weight: 600;
  background: #E1F3E6; color: #1E7B34; padding: 2px 8px; border-radius: 5px;
}
.pay-d { flex: 1; color: var(--muted); font-size: 12.5px; }
/* เลขที่ใบที่รับเงินไว้ — แสดงเมื่อในงานมีหลายใบ (แบ่งงวด) */
.pay-doc { flex: 0 0 auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pay-a { font-variant-numeric: tabular-nums; }
.pay-x {
  flex: 0 0 auto; width: 26px; height: 26px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--red); font-size: 11px; cursor: pointer;
}
.pay-add { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 11px; }
.pay-add .pay-btn { grid-column: 1 / -1; text-align: center; padding: 12px; }
/* ข้อความ "รับเงินครบแล้ว" ต้องกินเต็มความกว้าง ไม่งั้นจะไปอยู่ชิดซ้ายในช่องแรกของตาราง */
.pay-add .pay-full { grid-column: 1 / -1; }

/* ยอดค้างในแถวตาราง */
.row-paid:empty { display: none; }
.row-paid { margin-top: 5px; }
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 5px;
}
.pill.part { background: #FFE8D9; color: #B5521E; }
.pill.full { background: #E1F3E6; color: #1E7B34; }

/* ===== ประวัติการใช้งาน ===== */
.act-row { padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.act-row:last-child { border-bottom: 0; }
.act-1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.act-who { font-size: 13.5px; font-weight: 700; color: #111; }
.act-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.act-2 { display: flex; align-items: baseline; gap: 7px; margin-top: 4px; flex-wrap: wrap; }
.act-tag {
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--navy-soft); color: var(--navy);
  padding: 2px 8px; border-radius: 5px;
}
.act-detail { font-size: 12.5px; color: #444; line-height: 1.45; }
.act-doc { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.act-doc:empty { display: none; }

/* ประวัติในแผ่นรายละเอียด */
.sh-hist { margin-top: 4px; }
.hist {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid #f5f6f8; font-size: 12.5px;
}
.hist:last-child { border-bottom: 0; }
.hist-tag {
  flex: 0 0 auto; font-size: 11px; font-weight: 600;
  background: #EDF1F8; color: #2F5496;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap;
}
.hist-tx { flex: 1; color: #333; }
.hist-t { flex: 0 0 auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }

/* ===== หน้าเข้าใช้งาน (รหัสตัวเลข / ผู้ดูแล) ===== */
.lock-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px 16px; background: var(--navy);
}
.lock {
  background: #fff; border-radius: 18px;
  padding: 28px 22px 24px; width: 100%; max-width: 340px;
  text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.lock.wide { max-width: 380px; text-align: left; }
.lock-logo { width: 72px; height: auto; display: block; margin: 0 auto 14px; }
.lock.wide .lock-logo { margin-bottom: 14px; }
.lock-title { font-size: 19px; font-weight: 700; color: #111; }
.lock-sub { font-size: 13.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }
.lock-sub.err { color: var(--red); font-weight: 600; }
.lock.wide .lock-title, .lock.wide .lock-sub { text-align: center; }
.lock .go { margin-top: 18px; }
.lock-back {
  display: block; text-align: center; margin-top: 14px;
  font-size: 13.5px; color: var(--muted); text-decoration: none;
}

/* จุดแสดงจำนวนหลักที่กรอก */
.dots { display: flex; justify-content: center; gap: 11px; margin: 22px 0 24px; }
.dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  transition: transform .1s ease, background .1s ease;
}
.dot.on { background: var(--navy); border-color: var(--navy); transform: scale(1.1); }
.dots.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-9px); }
  40%,80% { transform: translateX(9px); }
}

/* แป้นตัวเลข */
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
.key {
  height: 62px; border-radius: 14px;
  border: 1px solid var(--line); background: #fff;
  font-family: inherit; font-size: 24px; font-weight: 600; color: #111;
  cursor: pointer; user-select: none;
}
.key:active { background: #eef2f9; transform: scale(.96); }
.key.del { font-size: 20px; color: var(--muted); }

/* ===== สายเอกสารในงานเดียวกัน ===== */
.chain {
  font-size: 10.5px; font-weight: 600; white-space: nowrap;
  background: #EAF6EC; color: #1E7B34;
  padding: 2px 6px; border-radius: 5px;
}
.sh-chain { margin-top: 4px; }
/* แถวเอกสาร — บรรทัดเดียว ทุกชิ้นอยู่กึ่งกลางแนวตั้ง
   ระยะขอบบนล่างเท่ากัน (6px) จึงดูบาลานซ์และเตี้ยลงกว่าเดิม */
.chain-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: 6px 8px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 9px;
  color: #222; font-size: 12.5px;
  white-space: nowrap; overflow: hidden;
}
.chain-row.cur { background: #F2F6FC; border-color: var(--navy-soft); }
.chain-row .tag { flex: 0 0 auto; }
.chain-no {
  flex: 0 1 auto; min-width: 0;
  font-variant-numeric: tabular-nums; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis;
}
.chain-amt {
  flex: 0 0 auto; margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--navy); white-space: nowrap;
}
.chain-open {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--navy); background: #fff;
  color: var(--navy); font-weight: 600; font-size: 12px;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  line-height: 1;
}
/* ปุ่มแก้ไข + ดูเอกสาร ของแต่ละใบ — ขึ้นบรรทัดใหม่ใต้ประเภท/เลขที่เอกสาร */
.chain-btns { flex: 0 0 100%; display: flex; gap: 6px; }
.chain-next { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
/* ปุ่มคู่กัน 2 ปุ่ม — ปุ่มที่ข้อความยาวจนตก 2 บรรทัด (บน iPhone ตัวอักษรไทยกว้างกว่า) จะดันให้อีกปุ่มสูงตาม
   จึงจัดข้อความให้อยู่กลางทั้งแนวนอนและแนวตั้ง ไม่ให้ลอยอยู่บนสุดของปุ่ม */
.chain-next .act {
  flex: 1 1 calc(50% - 4px); padding: 12px 8px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  white-space: nowrap;
}
/* จอแคบ (มือถือ) 2 ปุ่มยังอยู่แถวเดียวกัน ลดตัวอักษร/ระยะขอบให้ข้อความอยู่บรรทัดเดียว */
@media (max-width: 520px) {
  .chain-next { gap: 6px; }
  .chain-next .act { flex: 1 1 calc(50% - 3px); font-size: 12.5px; padding: 12px 4px; }
}

/* กล่องเตือนในแผ่นรายละเอียด */
.warn-box {
  background: #FDF0D5; color: #8A6400;
  border-radius: 9px; padding: 10px 12px; margin-top: 10px;
  font-size: 12.5px; font-weight: 600; line-height: 1.45;
}

/* ===== แถบสลับหน้า (งานทั้งหมด / ใบอนุญาต-วีซ่า) ===== */
.tabs {
  display: flex; gap: 0; background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.tab {
  flex: 1; text-align: center; padding: 12px 8px;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  text-decoration: none; border-bottom: 2.5px solid transparent;
}
/* แถบที่เป็นปุ่ม (หน้าเดียวสลับส่วน เช่น หลังบ้านผู้ดูแล) ให้หน้าตาเหมือนแถบที่เป็นลิงก์ */
button.tab { background: #fff; border: 0; border-bottom: 2.5px solid transparent; font-family: inherit; cursor: pointer; border-radius: 0; }
.tab.on { color: var(--navy); border-bottom-color: var(--navy); }
.tab:active { background: #f6f8fb; }
/* จุดแดงเตือนว่ามีของใกล้หมดอายุ */
.tab-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #C0392B; vertical-align: middle; margin-left: 3px;
}
.tab-dot[hidden] { display: none; }

/* ===== หน้าใบอนุญาต/วีซ่า ===== */
.stat.red .n { color: #C0392B; }
.badge.red { background: #FBE3E0; color: #C0392B; }

/* ชื่อบริการบนแถว กินพื้นที่ที่เหลือ ตัดท้ายถ้ายาว */
.row-svc-name {
  flex: 1; min-width: 0; font-size: 12px; color: #555;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.6;   /* กันสระไทยโดนตัดบน-ล่าง */
}
/* "เหลืออีกกี่วัน" ชิดขวา สีตามความเร่งด่วน */
.row-days {
  margin-left: auto; font-size: 13px; font-weight: 700;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.row-days.red    { color: #C0392B; }
.row-days.orange { color: #B5521E; }
.row-days.amber  { color: #8A6400; }
.row-days.green  { color: #1E7B34; }
.row-days.grey   { color: #777; }

.lic-from { flex: 1; min-width: 0; white-space: nowrap; }

/* ช่องกรอกในหน้ารายละเอียดวันหมดอายุ — เว้นห่างจากเส้นใต้หัวข้อ */
.sh-field { margin-top: 8px; }

/* ปุ่มลอยแบบ <button> (หน้าวันหมดอายุ) — .fab เดิมออกแบบไว้สำหรับ <a> */
button.fab { border: 0; font-family: inherit; cursor: pointer; }
button.fab[hidden] { display: none; }

/* ปุ่มยกเลิกใต้ปุ่มบันทึกในฟอร์มเพิ่มรายการ */
#btnCancel { margin-top: 8px; border-style: solid; border-color: var(--line); color: var(--muted); }

/* ฟอร์มเพิ่มรายการ: ลูกค้า "ใหม่" (พิมพ์เอง) / "ลูกค้า" (เลือกจากรายชื่อ) */
.cust-list {
  margin-top: 6px; max-height: 264px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.cust-opt {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; border-bottom: 1px solid #f0f2f5; background: #fff;
  font-family: inherit; color: inherit; cursor: pointer;
}
.cust-opt:last-child { border-bottom: 0; }
.cust-opt:active { background: #eef2f9; }
.cust-opt .n, .cust-picked .n { font-size: 14.5px; font-weight: 600; color: #111; line-height: 1.5; }
.cust-opt .s, .cust-picked .s { font-size: 12px; color: var(--muted); }
.cust-opt .s:empty, .cust-picked .s:empty { display: none; }
.cust-none { padding: 14px 12px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.5; }
.cust-picked {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--navy-soft); border-radius: 10px; background: #f0f4fa;
}
.cust-picked-tx { flex: 1; min-width: 0; }
.cust-picked .link-btn { flex: 0 0 auto; font-size: 13.5px; padding: 6px 2px; }

/* หน้าออกเอกสาร: ปุ่ม "เลือกลูกค้าเก่า" ใต้แถวสำนักงานใหญ่/สาขา + แผ่นเลือกลูกค้า */
.pick.cust-pick { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 12px 0 0; }
.pick.cust-pick svg {
  flex: 0 0 auto; width: 17px; height: 17px;
  fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round;
}
/* ในแผ่นเลือกลูกค้า ทั้งแผ่นเลื่อนได้อยู่แล้ว — รายชื่อไม่ต้องมีแถบเลื่อนของตัวเองซ้อน */
.cust-list.in-sheet { max-height: none; overflow: visible; margin-top: 2px; }
#custFound { margin: 7px 0 6px; min-height: 0; }
#custFound:empty { display: none; }
.cust-br { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
/* ที่อยู่บรรทัดเดียว ยาวเกินตัดท้าย (line-height สูงไว้ กันสระไทยโดนตัด) */
.cust-addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.6; }

/* ===== หน้าสรุปยอด ===== */

/* ตัวเลข 3 ช่อง: ค้างรับ (เต็มแถว) + รายรับเดือนนี้ / ปีนี้ */
.money { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.money-card {
  display: block; width: 100%; min-width: 0; text-align: left;
  background: #fff; border: 0; border-radius: 12px; padding: 11px 13px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  font-family: inherit; color: inherit;
}
button.money-card { cursor: pointer; }
button.money-card:active { background: #f6f8fb; }
.money-card.owe { grid-column: 1 / -1; background: #FDF0D5; }
.money-card .t { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.money-card .n {
  margin-top: 2px; font-size: 19px; font-weight: 700; line-height: 1.35;
  color: #1E7B34; font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.money-card .s { margin-top: 1px; font-size: 11.5px; color: var(--muted); }
.money-card.owe .t, .money-card.owe .s { color: #8A6400; }
.money-card.owe .n { font-size: 23px; color: #8A6400; }
.money-card .n small { font-size: 13px; font-weight: 600; }

/* ยอดรวมของช่วงที่เลือก */
.inc-total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 0 10px; border-bottom: 1px solid var(--line);
  font-size: 14px; color: #444;
}
.inc-total b { font-size: 19px; color: #1E7B34; font-variant-numeric: tabular-nums; }

/* แถวรายการรับเงิน: ลูกค้า + ยอด / ประเภท + เลขที่ + วันที่รับ / (จ่ายบางส่วน) */
.inc-row { padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.inc-row:last-child { border-bottom: 0; }
.inc-1 { display: flex; align-items: center; gap: 8px; }
.inc-cust {
  flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; color: #111;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.6;   /* กันสระไทยโดนตัด เพราะช่องนี้มี overflow: hidden */
}
.inc-amt { font-size: 14.5px; color: #1E7B34; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inc-2 {
  display: flex; align-items: center; gap: 7px;
  margin-top: 3px; font-size: 12px; color: var(--muted);
}
.inc-no { font-variant-numeric: tabular-nums; white-space: nowrap; }
.inc-date { margin-left: auto; white-space: nowrap; }
.inc-3 { margin-top: 6px; }
.empty.small { padding: 22px 10px; }

/* ปุ่มส่งออก CSV เป็นลิงก์ดาวน์โหลด — จางและกดไม่ได้ตอนไม่มีรายการ */
.go.csv { text-align: center; text-decoration: none; margin-top: 14px; }
.go.off { opacity: .45; pointer-events: none; }

/* ===== รายชื่อพนักงาน (หน้าผู้ดูแล) ===== */
.adm.staff { align-items: center; }
.sig-thumb {
  flex: 0 0 96px; height: 48px; padding: 3px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.sig-thumb img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.sig-thumb.none {
  background: #f7f8fa; border-style: dashed;
  font-size: 11px; color: var(--muted); text-align: center; line-height: 1.3;
}
.staff-acts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.link-btn {
  padding: 0; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--navy);
}
.link-btn.danger { color: var(--red); }

/* ฟอร์มเพิ่มพนักงาน — แยกจากรายชื่อด้วยเส้นคั่น */
.staff-add { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
/* ตัวอย่างลายเซ็นวางบนเส้นประ เหมือนบนเอกสารจริง */
.sig-stage {
  margin-top: 8px; padding: 14px 12px 8px;
  background: #fff; border: 1px dashed var(--line); border-radius: 10px;
  text-align: center;
}
.sig-stage img {
  position: relative; z-index: 1; display: block;
  max-width: 80%; max-height: 64px; margin: 0 auto -12px;
}
.sig-line { color: #333; font-size: 13px; letter-spacing: .5px; }
.sig-cap { margin-top: 4px; font-size: 12px; color: var(--muted); }
/* ช่องเลือกไฟล์ซ่อนไว้ (กดผ่านปุ่มแทน) — ไม่ใช้ display:none เพราะ iPhone บางรุ่นกดไม่ติด */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  overflow: hidden; opacity: 0; pointer-events: none;
}

/* ===== หลังบ้าน: หมวดบริการ (เพิ่มหมวด / ย้ายบริการข้ามหมวด) ===== */
.adm-group { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.adm-group::after { content: none; }
.adm-gx {
  flex: 0 0 auto; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  color: #C0392B; background: #fff; border: 1px solid #E8B4AE; border-radius: 6px; padding: 3px 8px;
}
.adm-empty { font-size: 12.5px; color: var(--muted); padding: 8px 2px 4px; line-height: 1.5; }
.adm .adm-grp {
  flex: 0 0 auto; width: auto; max-width: 42%; height: 34px; padding: 0 30px 0 8px; margin: 0;
  text-overflow: ellipsis;
  font-size: 12.5px; border-radius: 6px;
}

/* ===== หลังบ้าน: แก้ชื่อ/รายละเอียดบริการ =====
   ชื่อเดิม (เอกสารเก่ายังใช้) สีน้ำตาล · กางดูข้อความก่อนแก้ได้ · แถวที่กำลังแก้เป็นกล่องฟอร์มเต็มความกว้าง */
.adm-old { font-size: 11.5px; color: #8A5A12; margin-top: 3px; line-height: 1.45; }
.adm-old:empty { display: none; }
.adm.editing {
  display: block; margin: 8px 0; padding: 12px 12px 14px;
  background: #f6f8fb; border: 1px solid #dbe3ee; border-radius: 12px;
}
.sv-form-hd { font-size: 14.5px; font-weight: 700; color: var(--navy); margin-bottom: 2px; }
.sv-form .lbl:first-of-type { margin-top: 6px; }
.sv-form input[type=text], .sv-form textarea { background: #fff; }
.sv-form textarea { line-height: 1.45; }
.sv-note {
  margin-top: 12px; padding: 9px 11px; border-radius: 9px; line-height: 1.5;
  font-size: 12.5px; color: #1E6B30; background: #E6F4EA; border: 1px solid #B9DEC4;
}
.svh { margin-top: 8px; padding: 2px 12px; background: #f6f8fb; border-radius: 10px; }
.svh-item { padding: 9px 0; border-bottom: 1px solid #e6eaf0; }
.svh-item:last-child { border-bottom: 0; }
.svh-when { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.svh-row { display: flex; gap: 8px; font-size: 12.5px; line-height: 1.5; color: #333; }
.svh-row .k { flex: 0 0 104px; color: var(--muted); }
.svh-row .v { flex: 1; min-width: 0; word-break: break-word; }

/* ===== หลังบ้าน: ประวัติการแก้ไขเอกสาร (ฉบับก่อนแก้ / เอกสารที่ถูกลบ) ===== */
.ver { border-bottom: 1px solid #f0f2f5; }
.ver:last-child { border-bottom: 0; }
/* แถวเอกสาร — ทั้งแถวเป็นปุ่มกางลำดับการแก้ไข */
.ver-hd {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  padding: 11px 0; border: 0; background: none; text-align: left;
  font-family: inherit; color: inherit; cursor: pointer;
}
.ver-hd .badge { margin-top: 2px; }
.ver.open .ver-hd .adm-n { color: var(--navy); }
.ver-body { margin: 0 0 12px; padding: 2px 12px; background: #f6f8fb; border-radius: 10px; }
.vev { padding: 10px 0; border-bottom: 1px solid #e6eaf0; }
.vev:last-child { border-bottom: 0; }
.vev.delete .act-tag { background: #FBE3E0; color: #C0392B; }
.vev.edit_untracked .act-tag,
.vev.create .act-tag { background: #ECEEF1; color: #555; }
/* สิ่งที่เปลี่ยน: ค่าเดิมขีดฆ่าสีแดงเข้ม → ค่าใหม่ตัวหนาสีเขียว */
.vchg { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: #333; }
.vchg:empty { display: none; }
.vchg li { margin: 2px 0; word-break: break-word; }
.vchg .vc-l { color: var(--muted); }
.vchg s { color: #9a3b30; }
.vchg b { color: #1E7B34; }
.vev-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.vev-acts:empty { display: none; }
.vev-acts .act { padding: 8px 12px; font-size: 12.5px; }
/* ปุ่มเปิดฉบับก่อนแก้ ในรายการประวัติการใช้งาน */
.act-row .act-ver { margin-top: 6px; padding: 6px 11px; font-size: 12px; }

/* ===== หลังบ้าน: เมนู =====
   คอมพิวเตอร์ (จอกว้าง 760px ขึ้นไป) = เมนูด้านซ้ายติดอยู่ใต้แถบหัวตลอด
   มือถือ = ปุ่ม ☰ มุมซ้ายบน กดแล้วแผ่นเมนูสไลด์ออกมาจากซ้ายเกือบเต็มจอ (admin.js เปิด/ปิด) */
.menu-btn { display: none; }
.hd-sec { display: none; }
.hd-tx { min-width: 0; }
.adm-shell { display: flex; align-items: flex-start; }
.adm-nav {
  position: sticky; top: var(--hd-h, 63px); z-index: 15;
  flex: 0 0 224px; height: calc(100vh - var(--hd-h, 63px)); overflow-y: auto;
  background: #fff; border-right: 1px solid var(--line);
  padding: 12px 10px;
}
.nav-top { display: none; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin: 0 0 2px; padding: 10px 12px;
  border: 0; border-radius: 10px; background: none; color: #3d4450;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1.4;
  text-align: left; cursor: pointer;
}
.nav-item:hover { background: #f3f5f8; }
.nav-item.on { background: #E8EEF7; color: var(--navy); }
.nav-item:focus-visible { outline: 2px solid var(--navy); outline-offset: -2px; }
.nav-ic {
  flex: 0 0 22px; width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.nav-tx { flex: 1; min-width: 0; }
.nav-l { display: block; }
.nav-d { display: none; }
/* ตัวเลขแดงท้ายเมนู = เรื่องที่ค้างอยู่ (ตรวจสอบ / วันหมดอายุ) */
.nav-n {
  flex: 0 0 auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: #C0392B; color: #fff; text-align: center;
  font-size: 12px; font-weight: 700; line-height: 22px;
}
.nav-bg { display: none; }
/* เนื้อหาอยู่กลางพื้นที่ที่เหลือทางขวาของเมนู */
.adm-main { flex: 1 1 0; min-width: 0; max-width: 780px; }

@media (max-width: 759.98px) {
  .menu-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto; width: 40px; height: 40px; margin: -4px 6px -4px -8px; padding: 0;
    border: 0; border-radius: 10px; background: none; color: #fff; cursor: pointer;
  }
  .menu-btn:active { background: rgba(255,255,255,.18); }
  .menu-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  .menu-dot {
    position: absolute; top: 7px; right: 5px; width: 9px; height: 9px; border-radius: 50%;
    background: #FF6B57; box-shadow: 0 0 0 2px var(--navy);
  }
  /* แถบหัว 2 บรรทัด: หลังบ้านผู้ดูแล (เล็ก) / ชื่อเมนูที่เปิดอยู่ (ใหญ่) */
  .hd-tx { display: flex; flex-direction: column; line-height: 1.3; }
  .hd-tx .t { font-size: 12px; font-weight: 600; opacity: .8; overflow: visible; }
  .hd-sec { display: block; font-size: 17px; font-weight: 700; white-space: nowrap; }

  .adm-shell { display: block; }
  .adm-nav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 90;
    width: 86vw; max-width: 420px; height: auto;
    padding: 0 0 calc(16px + env(safe-area-inset-bottom));
    border-right: 0; box-shadow: 6px 0 28px rgba(0,0,0,.22);
    overscroll-behavior: contain;
    transform: translateX(-105%); visibility: hidden;
    transition: transform .26s ease, visibility 0s linear .26s;
  }
  .adm-nav.open { transform: none; visibility: visible; transition: transform .26s ease; }
  .nav-top {
    position: sticky; top: 0; z-index: 1;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-bottom: 6px; padding: calc(12px + env(safe-area-inset-top)) 12px 12px 18px;
    background: var(--navy); color: #fff;
  }
  .nav-title { font-size: 17px; font-weight: 700; }
  .nav-x {
    flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 50%;
    background: rgba(255,255,255,.14); color: #fff; font-size: 16px; cursor: pointer;
  }
  .nav-x:active { background: rgba(255,255,255,.28); }
  .nav-item { gap: 14px; margin: 0; padding: 12px 18px; border-radius: 0; font-size: 16.5px; }
  .nav-item:hover { background: none; }
  .nav-item:active { background: #f3f5f8; }
  .nav-item.on { background: #EEF3FA; box-shadow: inset 4px 0 0 var(--navy); }
  .nav-ic { flex-basis: 24px; width: 24px; height: 24px; }
  .nav-d { display: block; margin-top: 1px; font-size: 12.5px; font-weight: 400; color: var(--muted); line-height: 1.4; }
  .nav-bg {
    display: block; position: fixed; inset: 0; z-index: 89;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
    transition: opacity .26s ease;
  }
  .nav-bg.show { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
}

/* ===== หลังบ้าน: ข้อมูลลูกค้า — ก้อนละราย (จอกว้างเรียง 2 คอลัมน์) ===== */
#cuFilters { margin: 10px 0 0; }
#cuNote { padding-top: 4px; }
.cu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin-bottom: 10px; }
.cu-grid .empty { grid-column: 1 / -1; }
.cu {
  display: flex; flex-direction: column; min-width: 0;
  background: #fff; border-radius: 14px; padding: 13px 14px 11px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.cu-1 { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 5px; }
.cu-n { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; color: #111; line-height: 1.5; word-break: break-word; }
.cu-1 .badge { margin-top: 2px; }
/* ข้อมูลอยู่ด้านบน ส่วนท้าย (ออกเอกสารกี่ใบ) อยู่ล่างสุดของก้อนเสมอ แม้ก้อนข้าง ๆ จะสูงกว่า */
.cu-body { flex: 1; margin-bottom: 8px; }
.cu-kv { display: flex; gap: 10px; padding: 2px 0; font-size: 13px; line-height: 1.5; }
.cu-kv .k { flex: 0 0 90px; color: var(--muted); }
.cu-kv .v { flex: 1; min-width: 0; color: #222; white-space: pre-line; word-break: break-word; }
.cu-foot { padding-top: 8px; border-top: 1px solid #f0f2f5; font-size: 12px; color: var(--muted); }
.cu.gone .cu-n { color: #555; }
.cu.gone .cu-foot { color: #8A6400; }

/* ===== หลังบ้าน: งานที่ปิดแล้ว — เพิ่มวันหมดอายุหรือยัง ===== */
#fuFilters { margin-bottom: 4px; }
.fu { padding: 11px 0; border-bottom: 1px solid #f0f2f5; }
.fu:last-child { border-bottom: 0; }
.fu-1 { display: flex; align-items: flex-start; gap: 8px; }
.fu-cust { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 700; color: #111; line-height: 1.5; }
.fu-1 .badge { margin-top: 2px; }
.fu-2 { margin-top: 1px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fu-svcs { margin-top: 6px; }
.fu-svc { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 3px 0; font-size: 13px; line-height: 1.5; }
.fu-name { color: #222; }
.fu-ok { color: #1E7B34; font-weight: 600; text-decoration: none; }
.fu-no { color: #C0392B; font-weight: 700; }
.fu-acts { margin-top: 8px; }
.fu-acts .act { padding: 7px 12px; font-size: 12.5px; }

/* ===== หลังบ้าน: ตรวจสอบ — ข้อมูลที่ขัดกัน ===== */
#auFilters { margin-bottom: 4px; }
.au { padding: 11px 0; border-bottom: 1px solid #f0f2f5; }
.au:last-child { border-bottom: 0; }
.au-1 { display: flex; align-items: flex-start; gap: 8px; }
.au-title { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 700; color: #111; line-height: 1.5; }
.au-1 .badge { margin-top: 2px; }
.au-cust { margin-top: 1px; font-size: 12.5px; color: #333; font-weight: 600; line-height: 1.5; word-break: break-word; }
.au-detail { margin-top: 3px; font-size: 13px; color: #222; line-height: 1.55; word-break: break-word; }
.au-hint {
  margin-top: 6px; padding: 7px 10px; border-radius: 8px;
  background: #FFF6E5; color: #6B4E00; font-size: 12.5px; line-height: 1.5;
}
.au-hint:empty { display: none; }
.au-meta { margin-top: 5px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.au.fixed .au-meta { color: #1E7B34; }
/* แก้แล้ว / ไม่ต้องแก้ = จางลง ให้เรื่องที่ยังไม่แก้เด่นกว่า */
.au.fixed .au-title, .au.ignored .au-title { color: #555; }
.au-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.au-acts:empty { display: none; }
.au-acts .act { padding: 7px 12px; font-size: 12.5px; }
