:root {
  /* ---------- ดีไซน์ใหม่ (ต.ค. 2026) — โทนเขียว/ครีม ปรับตามไอเดียที่ เจ้าของระบบ ส่งภาพตัวอย่างมา ----------
     เขียวเข้ม = สีหลัก (header/แถบล่าง/ปุ่มหลัก), ครีม = พื้นหลังแอป, ส้ม/อำพัน = สีเตือน/accent รอง
     ชื่อตัวแปรเดิม (--green/--red/--blue ฯลฯ) คงไว้เหมือนเดิมทุกตัว เพราะทุกหน้าในแอป (34+ หน้า) อ้างอิง
     ตัวแปรชุดนี้อยู่แล้ว — แค่เปลี่ยนค่าจุดเดียวตรงนี้ ทุกหน้าก็เปลี่ยนตามทันทีโดยไม่ต้องแก้ทีละหน้า */
  --green: #1e4d36;
  --green-dark: #163b29;
  --green-light: #e4f0e6;
  --red: #c0392b;
  --red-light: #fdecea;
  --yellow: #b6692f;       /* เดิมสีเหลือง เปลี่ยนเป็นโทนอำพัน/คลาย ให้เข้ากับธีมใหม่ (ยังสื่อ "เตือน" เหมือนเดิม) */
  --yellow-light: #f6e9da;
  --blue: #2563a8;
  --blue-light: #e8f1fa;
  --purple: #7c4fa0;
  --purple-light: #f3ecf8;
  --gray: #6b7568;          /* ปรับให้เอียงไปทางเขียว-เทาเล็กน้อย ให้เข้าชุดกับธีมใหม่แทนเทาล้วน */
  --border: #ece6d6;
  --bg: #f8f4e9;            /* พื้นหลังครีมอุ่นๆ แทนเทาอ่อนเดิม */
  --text: #1c2b22;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(28,43,34,0.06);
  --zebra: #f7f4ea;
  --accent-gold: #f3b23e;   /* ใช้จุดเดียว: ตัวอักษรย่อผู้ใช้ที่ topbar */
  --font: 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
.neg-num { color: var(--red); font-weight: 700; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  width: 100%; max-width: 100vw; }
#app { min-height: 100vh; display: flex; flex-direction: column; width: 100%; max-width: 100vw; overflow-x: hidden; }

/* ---------- top bar ---------- */
.topbar { background: var(--green); color: #fff; padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top)); display: flex;
  align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: 0; z-index: 10;
  max-width: 100%; overflow: hidden; }
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.topbar .brand-icon { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,0.16);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.topbar .brand-icon svg { display: block; }
.topbar .brand-text { min-width: 0; overflow: hidden; }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.topbar .brand-sub { font-size: 11px; color: rgba(255,255,255,0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; justify-content: flex-end; }
.topbar .user-chip { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.14); border: none;
  color: #fff; border-radius: 999px; padding: 4px 8px 4px 4px; max-width: 32vw; cursor: pointer; }
.topbar .user-chip .avatar { width: 24px; height: 24px; border-radius: 999px; background: var(--accent-gold);
  display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #4a3000;
  flex-shrink: 0; }
.topbar .user-chip .avatar svg { width: 15px; height: 15px; stroke: #4a3000; }
.topbar .user-chip .uname { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar button.logout-btn { background: rgba(255,255,255,0.15); border: none; color: #fff; padding: 7px 9px;
  border-radius: 8px; font-size: 12px; flex: 0 0 auto; white-space: nowrap; display: flex; align-items: center; }
@media (max-width: 400px) {
  .topbar .user-chip .uname { display: none; }
}
@media (max-width: 340px) {
  .topbar h1 { font-size: 13px; }
}

/* ---------- content ---------- */
.content { flex: 1; padding: 14px; padding-bottom: 86px; max-width: 900px; width: 100%; margin: 0 auto; }
.card { background: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--border); }
h2.section-title { font-size: 15px; font-weight: 600; color: var(--green); margin: 4px 0 12px; }

/* ---------- bottom nav ---------- */
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 4px; padding: 8px 10px max(10px, env(safe-area-inset-bottom)); z-index: 10; }
.bottomnav a { flex: 1 1 0; text-align: center; font-size: 10.5px; font-weight: 500; color: var(--gray);
  text-decoration: none; padding: 7px 4px; border-radius: 14px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; }
.bottomnav a.active { color: var(--green); font-weight: 600; background: var(--green-light); }
.bottomnav .icon { display: flex; align-items: center; justify-content: center; }
.bottomnav .icon svg { display: block; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--gray); margin: 10px 0 4px; font-weight: 500; }
.req { color: var(--red); font-weight: 700; margin-left: 2px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; background: #fff; color: var(--text); font-family: var(--font); }
textarea { resize: vertical; min-height: 60px; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
button { font-family: var(--font); }
button.primary { background: var(--green); color: #fff; border: none; padding: 13px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; width: 100%; margin-top: 14px; }
button.secondary { background: #fff; border: 1px solid var(--border); color: var(--text); padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; }
button.danger { background: var(--red); color: #fff; border: none; padding: 9px 13px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; }
a.secondary { background: #fff; border: 1px solid var(--border); color: var(--text); padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; text-decoration: none; display: inline-block; white-space: nowrap; }
.msg { padding: 12px 14px; border-radius: var(--radius-sm); margin-top: 10px; font-size: 14px; }
.msg.error { background: var(--red-light); color: var(--red); }
.msg.success { background: var(--green-light); color: var(--green-dark); }
.msg.warning { background: var(--yellow-light); color: #7a4510; }

/* ---------- type grid (เมนูแบบการ์ดไอคอน: เมนูบันทึกรายการ/รายงาน/ตั้งค่า/ทางลัดหน้าหลัก ใช้ร่วมกันหมด) ---------- */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-btn { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 10px;
  text-align: center; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.type-btn:active { opacity: 0.85; }
.type-btn .emoji { font-size: 21px; display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 13px; background: var(--green-light); line-height: 1; color: var(--green); }
.type-btn .emoji .ico { display: block; }
.type-btn { transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
@media (hover: hover) { .type-btn:hover { border-color: #d9cfb6; box-shadow: 0 4px 14px rgba(28,43,34,0.08); transform: translateY(-1px); } }
.type-btn:active { transform: scale(0.98); }
.type-btn .lbl { font-size: 12.5px; font-weight: 600; line-height: 1.3; }

/* การ์ด "งานประจำวัน" ที่มีงานค้างจริง (เช่น 📋 งานค้างที่ต้องตรวจ) — แทนที่แถบเตือนลอยด้านบนหน้าหลักเดิม
   (เจ้าของระบบ ขอตัดออกเพราะรำคาญตา) ด้วยการเน้นที่ไอคอนแทน: ขอบ/ตัวหนังสือแดง + เด้งเบาๆ ให้สะดุดตา + ตัวเลขค้าง */
.type-btn.has-pending { border-color: var(--red); animation: pending-pulse 1.8s ease-in-out infinite; }
.type-btn.has-pending .emoji { background: var(--red-light); color: var(--red); }
.type-btn.has-pending .lbl { color: var(--red); font-weight: 700; }
.type-btn .pending-badge { position: absolute; top: 8px; right: 8px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 999px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center; line-height: 1; box-shadow: 0 0 0 2px #fff; }
@keyframes pending-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, 0); }
}

/* ---------- entry menu: กลุ่มประเภทรายการ (จัดกลุ่ม ซื้อเข้า/ขายเครดิต/ฝากขาย/เบิกตัวอย่าง/อื่นๆ) ----------
   เดิมใช้เส้นสีคั่นด้านซ้าย (border-left) เปลี่ยนมาเป็นจุดสีกลมๆ หน้าหัวข้อกลุ่มแทน ดูสะอาดและทันสมัยกว่า
   สีของแต่ละกลุ่มยังคุมสีไอคอนในการ์ดลูก (.type-btn .emoji) ของกลุ่มนั้นด้วย ให้แต่ละหมวดดูแยกจากกันชัดเจน */
.entry-group { padding-left: 2px; margin-bottom: 24px; }
.entry-group:last-of-type { margin-bottom: 8px; }
.entry-group-title { font-size: 14.5px; font-weight: 700; margin: 0 0 3px; display: flex; align-items: center; gap: 8px; }
.entry-group-title::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--green); flex-shrink: 0; }
.entry-group-desc { font-size: 12px; color: var(--gray); margin: 0 0 10px; padding-left: 16px; }
.entry-group.grp-blue .entry-group-title::before { background: var(--blue); }
.entry-group.grp-blue .type-btn .emoji { background: var(--blue-light); color: var(--blue); }
.entry-group.grp-green .entry-group-title::before { background: var(--green); }
.entry-group.grp-green .type-btn .emoji { background: var(--green-light); }
.entry-group.grp-yellow .entry-group-title::before { background: var(--yellow); }
.entry-group.grp-yellow .type-btn .emoji { background: var(--yellow-light); color: var(--yellow); }
.entry-group.grp-purple .entry-group-title::before { background: var(--purple); }
.entry-group.grp-purple .type-btn .emoji { background: var(--purple-light); color: var(--purple); }
.entry-group.grp-gray .entry-group-title::before { background: var(--gray); }
.entry-group.grp-gray .type-btn .emoji { background: #eee8d8; color: var(--gray); }
.entry-group.grp-red .entry-group-title::before { background: var(--red); }
.entry-group.grp-red .type-btn .emoji { background: var(--red-light); color: var(--red); }
.entry-group.grp-teal .entry-group-title::before { background: #0f7c80; }
.entry-group.grp-teal .type-btn .emoji { background: #e0f2f1; color: #0f7c80; }
.entry-group.grp-orange .entry-group-title::before { background: #c2660f; }
.entry-group.grp-orange .type-btn .emoji { background: #fdeedd; color: #c2660f; }
/* เมนูรายงาน (เจ้าของระบบ 2026-10-15): ค้นหา + คำอธิบายสั้นใต้ชื่อ + เปิดล่าสุด */
.rep-search { width: 100%; margin: 4px 0 18px; }
.type-btn .rep-hint { font-size: 11px; color: var(--gray); line-height: 1.3; margin-top: -4px; }
@media (min-width: 760px) { .rep-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .rep-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---------- kpi cards ---------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 14px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.kpi .num { font-size: 24px; font-weight: 700; color: var(--green); }
.kpi .lbl { font-size: 12px; color: var(--gray); margin-top: 2px; font-weight: 500; }
.kpi.warn .num { color: var(--yellow); }
.kpi.danger .num { color: var(--red); }
a.kpi { display: block; text-decoration: none; color: inherit; }
a.kpi:active { opacity: 0.7; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; overscroll-behavior-x: contain; cursor: grab; }
.table-wrap.dragging { cursor: grabbing; user-select: none; }
.sticky-hscroll { position: fixed; left: 0; width: 0; height: 16px; overflow-x: auto; overflow-y: hidden;
  background: #fff; border-top: 1px solid var(--border); z-index: 15; display: none; }
.sticky-hscroll.visible { display: block; }
.sticky-hscroll > div { height: 1px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th, td { border-right: 1px solid var(--border); }
th:last-child, td:last-child { border-right: none; }
/* คอลัมน์ "รายละเอียด" ของหน้า Audit Log — ของเดิม nowrap ทุกคอลัมน์ ทำให้รายการยาวๆ (เช่น ราคาล็อกลูกค้า
   หลายสิบตัว) ดันตารางทั้งหน้ากว้างเกิน ต้องเลื่อนขวาดู (เจ้าของระบบ แจ้ง 2026-10-03) — จำกัดความกว้างไว้แล้วให้ตัดขึ้น
   บรรทัดใหม่แทน ดู auditListHtml ฝั่ง JS ที่พับรายการยาวไว้ใน <details> ด้วยอีกชั้น */
td.audit-detail { white-space: normal; text-align: left; max-width: 360px; word-break: break-word; }
tbody tr:nth-child(even) td { background: var(--zebra); }
thead th { background: #faf7ef; color: var(--gray); font-weight: 600; position: sticky; top: 0; z-index: 1; }
tr.level-danger td.stockcell { background: var(--red-light); color: var(--red); font-weight: 700; }
tr.level-warning td.stockcell { background: var(--yellow-light); color: var(--yellow); font-weight: 700; }
tr.level-ok td.stockcell { color: var(--green); font-weight: 600; }

td.freeze, th.freeze {
  position: sticky; left: 0; background: #fff; z-index: 2;
  box-shadow: 2px 0 4px -2px rgba(0,0,0,0.15);
  white-space: normal; max-width: 140px;
}
thead th.freeze { background: #faf7ef; z-index: 3; }
tbody tr:nth-child(even) td.freeze { background: var(--zebra); }

.year-table th, .year-table td { border-right: 1px solid var(--border); }
.year-table thead tr:first-child th:not(.freeze) { text-align: center; }
.year-table th.month-end, .year-table td.month-end { border-right: 2px solid var(--gray); }
.year-table th:last-child, .year-table td:last-child { border-right: none; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; max-width: 100%; }
.filters > * { flex: 1 1 120px; min-width: 0; max-width: 100%; }
/* มือถือจอแคบ (เจ้าของระบบ แจ้ง 2026-10-03 ว่าหลายหน้ารายงานล้นจอบน Safari iPhone) — select/input วันที่ของ Safari
   บางรุ่นมีความกว้างขั้นต่ำภายในที่ไม่ยอมหดตาม flex-shrink/min-width:0 เหมือน browser อื่น ถ้ามี 2 ช่องอยู่แถว
   เดียวกันบนจอแคบมากๆ อาจดันล้นออกนอกจอได้เล็กน้อย — ให้แถวตัวกรองวางแนวตั้งทีละช่องเสมอบนจอแคบ ตัดปัญหานี้ทั้ง
   หมดโดยไม่ต้องพึ่งการคำนวณความกว้างที่ไว้ใจเบราว์เซอร์แต่ละตัวไม่ได้ (ใช้ร่วมกันทุกหน้ารายงานผ่าน .filters)
   ยังคงวางแถวเดียวกันได้ตามปกติบนจอกว้างกว่านี้เหมือนเดิม (ไม่กระทบ desktop/แท็บเล็ต) */
@media (max-width: 480px) {
  .filters > * { flex-basis: 100%; }
}

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.in { background: var(--green-light); color: var(--green); }
.badge.out { background: var(--red-light); color: var(--red); }

.center { text-align: center; }
.muted { color: var(--gray); font-size: 13px; }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--bg); }
.login-box { background: #fff; border-radius: 22px; padding: 32px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 8px 28px rgba(28,43,34,0.10); }
.login-box .logo-badge { width: 52px; height: 52px; border-radius: 16px; background: var(--green);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.login-box h1 { text-align: center; color: var(--text); font-size: 18px; font-weight: 700; margin: 0 0 2px; }
.login-box .sub { text-align: center; color: var(--gray); font-size: 13px; margin-bottom: 18px; }

.checkbox-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 0; }
.checkbox-list input { width: auto; }

.list-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.list-row:last-child { border-bottom: none; }
.list-row .main { font-size: 14px; }
.list-row .sub { font-size: 12px; color: var(--gray); }

/* ---------- ไอคอน "?" คำอธิบายเพิ่มเติม ---------- */
.info-tip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  border-radius: 50%; background: var(--border); color: var(--gray); font-size: 11px; font-weight: 700;
  cursor: help; margin-left: 5px; position: relative; vertical-align: middle; flex: 0 0 auto; user-select: none; }
.info-tip .tip-bubble { display: none; position: absolute; z-index: 20; left: 50%; top: calc(100% + 6px);
  transform: translateX(-50%); background: #2b2f26; color: #fff; font-size: 12px; font-weight: 400;
  line-height: 1.5; padding: 8px 10px; border-radius: 8px; width: max-content; max-width: min(78vw, 320px);
  white-space: normal; text-align: left; box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.info-tip .tip-bubble a { color: #9fd3ff; }
.info-tip .tip-bubble::before { content: ""; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%); border: 5px solid transparent; border-bottom-color: #2b2f26; }
@media (hover: hover) { .info-tip:hover .tip-bubble { display: block; } }
.info-tip.open .tip-bubble { display: block; }

/* ---------- ตารางรายงานบนมือถือ ----------
   ต้นเหตุจริงของอาการ "ล้นจอ/ตัวเลขโดนตัด" ในรายงาน (เจ้าของระบบ แจ้ง 2026-10-03 จากหน้าสต๊อกฝากขายรายลูกค้า): ทุกช่อง
   ในตารางตั้งไว้ไม่ให้ตัดบรรทัด (nowrap) ชื่อสินค้ายาวๆ ในคอลัมน์แรกจึงดันคอลัมน์ตัวเลขสำคัญ (เช่น "คงเหลือ") ไปอยู่
   นอกจอ ต้องปัดตารางไปทางขวาถึงจะเห็น — บนจอแคบให้คอลัมน์แรก (ชื่อสินค้า/ลูกค้า) และหัวตารางตัดขึ้นบรรทัดใหม่ได้
   ตารางเล็ก (2-4 คอลัมน์) จะพอดีจอทันทีไม่ต้องปัด ส่วนตารางกว้างมาก (เช่นรายงาน 12 เดือน) ยังปัดดูได้ตามเดิม
   ตัวเลขในคอลัมน์อื่นยังไม่ตัดบรรทัดเหมือนเดิม (อ่านง่าย ไม่แตกเป็นสองแถว) */
@media (max-width: 600px) {
  .table-wrap th, .table-wrap td:first-child { white-space: normal; }
  .table-wrap td:first-child, .table-wrap th:first-child { min-width: 7.5em; }
}

/* ---------- จอแคบ (มือถือ) ---------- */
@media (max-width: 420px) {
  .content { padding: 10px; padding-bottom: 86px; }
  .card { padding: 12px; }
  table { font-size: 12px; }
  th, td { padding: 7px 7px; }
  td.freeze, th.freeze { max-width: 110px; }
}

/* ================= เฟส 3 (2026-10-03): หน้าตาทันสมัยขึ้น ================= */

/* ---- โครงหน้าระหว่างโหลด (skeleton) แทนข้อความ "กำลังโหลด..." ---- */
.skeleton .sk-title, .skeleton .sk-line, .skeleton .sk-block {
  border-radius: 8px; margin-bottom: 12px;
  background: linear-gradient(90deg, #efe9da 25%, #f8f4ea 37%, #efe9da 63%);
  background-size: 400% 100%; animation: sk-shimmer 1.3s ease-in-out infinite;
}
.skeleton .sk-title { height: 22px; width: 55%; margin-bottom: 18px; }
.skeleton .sk-line { height: 12px; }
.skeleton .sk-block { height: 110px; margin: 18px 0; }
@keyframes sk-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton .sk-title, .skeleton .sk-line, .skeleton .sk-block { animation: none; } }

/* ---- แผงตัวกรองพับได้ (มือถือ) — สร้างโดย enhanceFilters() ใน js/core.js ---- */
.filters-panel { margin-bottom: 10px; }
.filters-toggle { display: flex; align-items: center; gap: 8px; width: 100%; justify-content: flex-start;
  background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.filters-toggle .chev { margin-left: auto; transition: transform .15s ease; }
.filters-panel.open .filters-toggle .chev { transform: rotate(180deg); }
.filters-panel .filters-body { display: none; padding-top: 10px; }
.filters-panel.open .filters-body { display: block; }
.filters-panel .filters:last-child { margin-bottom: 0; }

/* ---- ตารางแสดงเป็นการ์ดบนมือถือ (table.cardify) — ป้ายชื่อช่องมาจาก enhanceCardTables() ---- */
@media (min-width: 601px) { table.audit-table { min-width: 760px; } }
@media (max-width: 600px) {
  .cardify-wrap { overflow-x: visible; }
  table.cardify, table.cardify tbody { display: block; width: 100%; }
  table.cardify thead { display: none; }
  table.cardify tr { display: block; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 6px 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
  table.cardify td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    border: none; border-bottom: 1px dashed var(--border); padding: 7px 0; white-space: normal; text-align: right;
    background: transparent !important; min-width: 0; max-width: none; }
  table.cardify td:last-child { border-bottom: none; }
  table.cardify td:empty { display: none; }
  table.cardify td { padding: 6px 0; font-size: 13px; }
  table.cardify td::before { content: attr(data-label); color: var(--gray); font-weight: 600; font-size: 12px;
    text-align: left; flex: 0 0 auto; max-width: 40%; }
  table.cardify td:not([data-label])::before { content: none; }
  table.cardify td.card-full { display: block; text-align: center; }
  table.cardify td .toolbar { justify-content: flex-end; }
  table.cardify td.audit-detail { display: block; text-align: left; }
  table.cardify td.audit-detail::before { display: block; max-width: none; margin-bottom: 4px; }
  table.cardify .audit-full-table { display: table; }
  table.cardify .audit-full-table tbody { display: table-row-group; }
  table.cardify .audit-full-table tr { display: table-row; border: none; box-shadow: none; padding: 0; margin: 0; background: transparent; }
  table.cardify .audit-full-table th, table.cardify .audit-full-table td { display: table-cell; text-align: left;
    border: 1px solid var(--border); padding: 3px 6px; font-size: 12px; }
  table.cardify .audit-full-table td::before { content: none; }
  table.cardify .audit-full-table tr.audit-changed td { background: var(--yellow-light) !important; }
}

/* ---- แถบปุ่มบันทึกบิลติดขอบล่างจอ (เหนือแถบเมนูล่าง) — กดบันทึกได้ทันทีไม่ต้องเลื่อนลงไปหา ---- */
.bill-actions { position: sticky; bottom: calc(62px + max(10px, env(safe-area-inset-bottom))); z-index: 5;
  display: flex; align-items: center; gap: 12px; margin: 16px -16px 0; padding: 12px 16px;
  background: rgba(255,255,255,0.96); border-top: 1px solid var(--border);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.bill-actions .bill-count { font-size: 13px; color: var(--gray); white-space: nowrap; }
.bill-actions button { flex: 1 1 auto; margin: 0; }
@media (max-width: 420px) { .bill-actions { margin: 14px -12px 0; padding: 10px 12px; } }

/* ---- ปุ่ม/การ์ด: ตอบสนองตอนแตะ + เส้นโฟกัสชัดเจนเวลาใช้คีย์บอร์ด ---- */
button, a.secondary, .type-btn { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- บรรทัดสินค้าในฟอร์มคีย์บิลบนมือถือ: เรียงเป็นการ์ด (สินค้าเต็มแถว / จำนวน + ราคา / หมายเหตุ) ไม่ต้องปัดขวา ---- */
@media (max-width: 600px) {
  table.bill-lines, table.bill-lines tbody { display: block; width: 100%; }
  table.bill-lines thead { display: none; }
  table.bill-lines tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: start;
    border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 10px; background: #fff; }
  table.bill-lines td { display: block; border: none; padding: 0; min-width: 0 !important; width: auto !important;
    white-space: normal; background: transparent !important; text-align: left; }
  table.bill-lines td.lc-product { grid-column: 1 / 3; grid-row: 1; }
  table.bill-lines td.lc-remove { grid-column: 3; grid-row: 1; }
  table.bill-lines td.lc-qty { grid-column: 1; grid-row: 2; }
  table.bill-lines td.lc-note { grid-column: 2 / 4; grid-row: 2; }
  table.bill-lines.has-price td.lc-price { grid-column: 2 / 4; grid-row: 2; }
  table.bill-lines.has-price td.lc-note { grid-column: 1 / 4; grid-row: 3; }
  table.bill-lines .ln_remove { height: 44px; }
}

/* #app เดิมใช้ overflow-x: hidden ซึ่งทำให้ position: sticky ข้างในไม่ทำงาน (แถบบันทึกบิล/หัวตาราง) —
   overflow-x: clip ตัดส่วนเกินเหมือนเดิมแต่ไม่สร้างกล่องเลื่อนใหม่ (เบราว์เซอร์เก่าที่ไม่รองรับใช้ค่าเดิมต่อไป) */
@supports (overflow-x: clip) {
  html, body, #app { overflow-x: clip; }
}

/* ไอคอนเส้นในหัวข้อหน้า (แทนอีโมจิ) */
.section-title .ico { vertical-align: -3px; margin-right: 4px; flex-shrink: 0; }
.group-head { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--green); }

/* audit log: รายละเอียดเต็มของแต่ละแถว (v3.0 รอบ 3) */
.audit-sub { margin-top: 2px; }
.audit-full { margin-top: 6px; }
.audit-full > summary { cursor: pointer; color: var(--blue); font-size: 13px; }
.audit-full-table { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 12px; }
.audit-full-table th, .audit-full-table td { border: 1px solid var(--border, #e5e7eb); padding: 3px 6px; text-align: left; vertical-align: top; word-break: break-word; }
.audit-full-table tr.audit-changed td { background: var(--yellow-light); }
.log-search { display: flex; gap: 8px; margin: 10px 0; }
.log-search input { flex: 1; min-width: 0; }
.msg.info { background: var(--blue-light); color: var(--blue); }
.m-0 { margin: 0; }
.mt-8 { margin-top: 8px; }
.bill-lock-note { margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.bill-header-link { padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.bh-lines { margin-top: 10px; }
.bh-lines summary { cursor: pointer; color: var(--blue); }
.btn-pad { padding: 8px 14px; border-radius: 8px; }
td.num { text-align: right; white-space: nowrap; }
tr.total-row td { background: var(--green-light); }
.warn-chip { font-size: 11px; color: var(--yellow); white-space: nowrap; }
.scan-row { display: flex; gap: 8px; margin: 0 0 6px; }
.scan-row input { flex: 1; min-width: 0; }
.scan-msg { font-size: 13px; min-height: 18px; margin-bottom: 6px; color: var(--green-dark); }
.mb-8 { margin-bottom: 8px; }

/* ===== ย้ายจาก inline style= (v3.0 รอบ 3) เพื่อปิด 'unsafe-inline' ใน CSP — สร้างอัตโนมัติด้วย tools/convert_styles.py =====
   ใส่ !important เพื่อให้ทับกฎอื่นได้เหมือน inline style เดิม (ยกเว้น property ที่ JS ปรับทีหลัง เช่น display) */
.su-002535 { margin-top: 12px !important; }
.su-02365d { padding-bottom: 4px !important; }
.su-034d12 { opacity: 0.55 !important; padding: 12px 16px !important; }
.su-0fa155 { border: none !important; padding: 0 !important; background: transparent; font-size: 14px !important; }
.su-1386d5 { margin: 0 !important; }
.su-152fc2 { margin-top: 14px !important; background: var(--bg2, #f7f5ef); padding: 12px !important; border-radius: 8px !important; }
.su-18d1b7 { flex-direction: column !important; align-items: stretch !important; border: 1px dashed var(--border) !important; border-radius: 8px !important; padding: 10px !important; }
.su-1a3055 { width: 110px; }
.su-1ab60b { padding: 6px 12px !important; border-radius: 8px !important; font-size: 13px !important; }
.su-26f988 { gap: 8px !important; flex-wrap: wrap !important; align-items: center !important; margin-top: 10px !important; }
.su-2937bf { margin-bottom: 6px !important; }
.su-2cbdcc { margin: 4px 0 4px !important; }
.su-2de001 { color: var(--yellow) !important; font-weight: 700 !important; }
.su-2f01ef { width: 140px; }
.su-3044b6 { font-size: 13px !important; }
.su-304cd5 { gap: 8px !important; }
.su-359f30 { margin-bottom: 12px !important; font-size: 13px !important; }
.su-3645bc { border-top: 1px solid var(--border) !important; margin-top: 10px !important; padding-top: 10px !important; }
.su-36d0ca { margin-top: 8px !important; width: 100%; }
.su-3aa131 { color: var(--red) !important; font-weight: 600 !important; }
.su-3f9f96 { min-width: 0 !important; }
.su-416c26 { padding: 10px 0 !important; }
.su-440e7c { max-height: 220px !important; overflow: auto !important; border: 1px solid var(--border) !important; border-radius: 8px !important; padding: 8px !important; }
.su-483843 { margin-top: 8px !important; font-weight: 700 !important; font-size: 16px !important; }
.su-4a9302 { min-width: 140px !important; }
.su-4b376a { margin-top: 10px !important; font-size: 12px !important; }
.su-4c7048 { margin-top: 4px !important; font-size: 12px !important; }
.su-4c7b29 { margin: 0 0 8px !important; }
.su-4ddbe9 { white-space: nowrap !important; }
.su-4f1589 { width: auto; }
.su-536f83 { color: var(--yellow) !important; }
.su-5371db { margin-top: 10px !important; }
.su-58f8fc { margin-bottom: 16px !important; padding-bottom: 14px !important; border-bottom: 1px solid var(--border) !important; }
.su-5cd105 { flex-shrink: 0 !important; }
.su-633669 { padding: 12px 0 4px !important; }
.su-6360c1 { grid-column: 1/-1 !important; padding: 10px 0 !important; }
.su-684f3e { border: 1px dashed var(--border) !important; border-radius: 8px !important; padding: 10px !important; margin-bottom: 12px !important; }
.su-69e683 { width: 220px; }
.su-6b283c { padding: 10px !important; }
.su-6b9c17 { font-size: 12px !important; }
.su-702a72 { color: var(--red) !important; font-size: 11px !important; margin-top: 2px !important; }
.su-716b3d { padding: 6px 0 !important; }
.su-729192 { width: 130px; }
.su-7a417f { margin: 18px 0 8px !important; }
.su-7e3f61 { padding: 40px !important; color: #6b7280 !important; }
.su-800eb2 { margin: 4px 0 8px !important; color: var(--red) !important; }
.su-81603d { color: var(--red) !important; margin-top: 2px !important; }
.su-8b6852 { font-size: 11px !important; }
.su-8e8697 { margin-bottom: 16px !important; }
.su-923e95 { min-width: 180px !important; }
.su-93de2d { width: 40px; }
.su-941456 { margin-bottom: 14px !important; padding-bottom: 12px !important; border-bottom: 1px solid var(--border) !important; }
.su-959bb5 { gap: 6px !important; }
.su-95be1a { margin: 10px 0 12px !important; }
.su-9a0569 { width: auto; flex: 0 0 auto !important; }
.su-9e3c4c { margin-top: 6px !important; }
.su-a18ac8 { margin-top: 4px !important; }
.su-a7333a { gap: 8px !important; flex-wrap: wrap !important; align-items: center !important; }
.su-a7409f { margin-bottom: 10px !important; }
.su-aca490 { padding: 8px 14px !important; border-radius: 8px !important; }
.su-af1410 { color: var(--yellow) !important; font-size: 12px !important; }
.su-b202c6 { cursor: pointer !important; }
.su-b2c4dc { color: #ffd9a0 !important; font-weight: 700 !important; }
.su-b7d39c { justify-content: flex-end !important; margin-top: 10px !important; }
.su-c7bbb8 { max-height: 260px !important; overflow: auto !important; border: 1px solid var(--border) !important; border-radius: 8px !important; padding: 8px !important; }
.su-c90c50 { gap: 6px !important; margin-top: 8px !important; }
.su-d43169 { margin-top: 8px !important; }
.su-d51702 { margin-bottom: 8px !important; }
.su-d6d39a { min-width: 1080px !important; }
.su-d892c0 { margin-top: 8px !important; font-size: 13px !important; }
.su-e09362 { color: var(--red) !important; }
.su-e10f65 { padding: 6px 12px !important; border-radius: 8px !important; }
.su-e27a38 { margin-top: 4px !important; font-size: 13px !important; }
.su-e396da { font-size: 12px !important; margin-top: 6px !important; }
.su-e9e69a { padding: 4px 8px !important; border-radius: 6px !important; font-size: 12px !important; }
.su-ec0d7a { gap: 6px !important; flex-wrap: nowrap !important; }
.su-eda06f { padding: 6px 10px !important; }
.su-ee0c30 { margin: 16px 0 8px !important; }
.su-f005b8 { margin-top: 2px !important; }
.su-f41bf6 { flex-wrap: wrap !important; gap: 8px !important; }
.su-f49ccb { margin: 4px 0 8px !important; }
.su-f65bbf { color: var(--yellow) !important; margin-top: 2px !important; }
.su-f6e3d7 { text-align: right !important; }
.su-fa3e1c { margin-bottom: 12px !important; }
.su-ff9224 { flex: 1 1 160px !important; }
.switch-row { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 14px; cursor: pointer; }
.switch-row input { width: auto; }
.badge-discontinued { font-size: 11px; background: var(--yellow-light); color: #7a4510; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.list-row.is-discontinued .main { color: var(--gray); }

/* ---- ล็อต / วันหมดอายุ (v3.0 รอบ 4) ---- */
.lc-lot input { margin-bottom: 4px; }
.ln_exp_lbl { display: block; font-size: 11px; }
@media (max-width: 600px) {
  table.bill-lines.has-lot td.lc-lot { grid-column: 2 / 4; grid-row: 2; }
  table.bill-lines.has-lot td.lc-note { grid-column: 1 / 4; grid-row: 3; }
}
.lot-confirm { margin-top: 14px; padding: 12px; border: 2px solid var(--blue); border-radius: var(--radius-sm); background: var(--blue-light); }
.lot-confirm[hidden] { display: none; }
.lot-editor { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 10px; }
.lot-editor.lot-changed { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--yellow-light); }
.lot-head { margin-bottom: 6px; }
.lot-row { display: grid; grid-template-columns: 1fr 96px auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.lot-row select, .lot-row input { margin: 0; min-width: 0; }
.lot-del { padding: 6px 10px; }
.lot-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; font-size: 13px; }
.lot-note-wrap { margin-top: 6px; }
.lot-note-wrap.lot-note-required label::after { content: " *"; color: var(--red); }
.lot-current { font-size: 14px; }
.lot-task-card { border-left: 4px solid var(--blue); }
tr.lot-level-expired td { background: var(--red-light); }
tr.lot-level-soon td { background: var(--yellow-light); }
.lot-level-tag { font-size: 12px; font-weight: 600; }
.lot-consign-list { font-size: 11px; }
@media (max-width: 600px) {
  .lot-row { grid-template-columns: 1fr auto; }
  .lot-row .lot-sel { grid-column: 1 / -1; }
}

/* ---- ช่องล็อตในบรรทัดบิล (v3.0 รอบ 4b) ---- */
[hidden] { display: none !important; }
table.bill-lines td.lc-lot { min-width: 300px; }
.lot-cell { display: flex; flex-direction: column; gap: 4px; }
.lot-sub { display: grid; grid-template-columns: 1fr 84px auto; gap: 6px; align-items: center; }
.lot-sub select, .lot-sub input { margin: 0; min-width: 0; }
.lot-sub .lot-new { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 150px; gap: 6px; }
.lot-sub .lot-del { padding: 6px 10px; }
.lot-cell-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
.lot-cell-foot button { padding: 4px 10px; font-size: 12px; }
.lot-line-status { font-size: 12px; }
.lot-line-status.lot-warn { color: #7a4510; font-weight: 600; }
.lot-line-status.lot-err { color: var(--red); font-weight: 700; }
.lot-hint { font-size: 12px; padding: 6px 0; }
@media (max-width: 600px) {
  table.bill-lines.has-lot td.lc-lot { grid-column: 1 / 4; grid-row: 3; min-width: 0; }
  table.bill-lines.has-lot.has-price td.lc-lot { grid-row: 3; }
  table.bill-lines.has-lot td.lc-qty { grid-column: 1 / 4; }
  table.bill-lines.has-lot.has-price td.lc-qty { grid-column: 1; }
  .lot-sub .lot-new { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) { table.bill-lines:not(.has-price) td.lc-qty { grid-column: 1 / 4; } }
table.bill-lines td.lc-lot { min-width: 380px; width: 46%; }
table.bill-lines td.lc-product { min-width: 160px; }
.lot-subs .lot-sub:only-child .lot-del { visibility: hidden; }
@media (max-width: 600px) {
  table.bill-lines td.lc-lot { width: auto; }
  .lot-sub { grid-template-columns: 1fr auto; }
  .lot-sub .lot-sel { grid-column: 1 / -1; }
}

/* ---- ช่องล็อต รอบ 4c: ปุ่มลบเล็ก/ต่างจากปุ่มลบรายการ, ฟอร์มรับเข้าแบบ 3 ช่องเรียงกัน ---- */
button.line-del { background: #fff; color: var(--red); border: 1px solid var(--red-light); border-radius: var(--radius-sm);
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; }
button.line-del:hover { background: var(--red-light); }
table.bill-lines .ln_remove.line-del { height: 40px; }
button.lot-del { background: transparent; border: none; color: var(--gray); font-size: 20px; line-height: 1;
  width: 28px; height: 28px; padding: 0; border-radius: 50%; cursor: pointer; }
button.lot-del:hover { background: var(--border); color: var(--red); }
.lot-subs .lot-sub:only-child .lot-del { visibility: hidden; }
button.link-btn { background: none; border: none; color: var(--blue); padding: 2px 4px; font-size: 13px; font-weight: 600; cursor: pointer; }
button.link-btn:hover { text-decoration: underline; }
.lot-sub { grid-template-columns: 1fr 84px 28px; }
.lot-cap { display: grid; grid-template-columns: 1fr 120px 76px 28px; gap: 6px; font-size: 11px; color: var(--gray); font-weight: 600; }
.lot-sub.lot-sub-entry { grid-template-columns: 1fr 120px 76px 28px; }
.lot-sub-entry .lot-tag { grid-column: 1 / -1; font-size: 11px; margin-top: -2px; }
.lot-tag.is-old { color: var(--blue); }
.lot-tag.is-new { color: var(--green); }
.lot-sub-entry .lot-exp[readonly] { background: var(--bg); color: var(--gray); }
input.is-invalid { border-color: var(--red) !important; background: var(--red-light); }
/* ช่องวันที่ วว/ดด/ปปปป (core.js enhanceDateInput) — ช่องเดิมของเบราว์เซอร์โปร่งใส ทับไอคอนปฏิทินด้านขวา */
.date-field { position: relative; display: block; width: 100%; }
.toolbar .date-field, .mc-setmonth .date-field { display: inline-block; width: auto; min-width: 150px; }
.date-field .date-text { width: 100%; padding-right: 40px; }
.date-field::after { content: "📅"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; font-size: 16px; opacity: .75; }
.date-field .date-native { position: absolute; right: 0; top: 0; width: 40px; height: 100%; opacity: 0; padding: 0; margin: 0; border: 0; cursor: pointer; }
.date-field .date-native::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
@media (max-width: 600px) {
  .lot-sub { grid-template-columns: 1fr 84px 28px; }
  .lot-sub .lot-sel { grid-column: 1 / -1; }
  .lot-cap, .lot-sub.lot-sub-entry { grid-template-columns: 1fr 1fr 64px 28px; }
  .lot-sub.lot-sub-entry .lot-no { grid-column: auto; }
}
.lot-cell, .lot-cap, .lot-line-status, .lot-tag { text-align: left; }
.lot-cell-foot { justify-content: flex-start; }
/* บรรทัดแรกของบิลไม่มีปุ่มลบ (ต้องมีอย่างน้อย 1 บรรทัด) */
#billLinesBody tr:first-child .ln_remove { visibility: hidden; pointer-events: none; }
.lot-appr { font-size: 12px; margin-left: 8px; }
.lot-appr-flag { font-size: 12px; color: #7a4510; background: var(--yellow-light); border-radius: 8px; padding: 4px 8px; margin: 2px 0 4px 8px; }

/* ---- รอบ 5: ล็อกสินค้ากับคู่ค้า + ส่วนลดท้ายบิล ---- */
.pp-hint { font-size: 12px; margin: 2px 0 6px; }
.pp-hint:empty { display: none; }
.discount-row { display: grid; grid-template-columns: 160px 1fr; gap: 10px; }
@media (max-width: 600px) { .discount-row { grid-template-columns: 1fr; } }
/* หน้าแก้ไข Supplier/ลูกค้า: แบ่งเป็นการ์ด ไม่พับเก็บ */
.pe-h { margin: 0 0 10px; font-size: 16px; }
.pe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.pe-grid .pe-wide { grid-column: 1 / -1; }
.pe-check { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; font-weight: normal; cursor: pointer; }
.pe-check input { margin-top: 3px; }
.pe-actions { padding-top: 14px; padding-bottom: 14px; }
.pe-actions .toolbar { margin: 0; }
.ppm-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.ppm-tools .ppm-search { flex: 1 1 220px; margin: 0; }
.ppm-tools select { width: auto; margin: 0; }
.ppm-summary { margin: 4px 0 8px; }
.ppm-wrap { max-height: 60vh; overflow: auto; }
.ppm-table { width: 100%; }
.ppm-table thead th { position: sticky; top: 0; background: var(--card, #fff); z-index: 1; }
.ppm-table .ppm-chk { width: 78px; text-align: center; }
.ppm-table .ppm-chk input { width: 20px; height: 20px; margin: 0; }
.ppm-table .ppm-price { width: 130px; }
.ppm-table .ppm-price input { margin: 0; }
.ppm-sub { font-size: 11px; }
.ppm-table .ppm-shelf { width: 140px; }
.ppm-table .ppm-shelf input { margin: 0; }
.ppm-shelf-sub { font-size: 11px; white-space: normal; line-height: 1.3; }
.ppm-shelf-sub .link-btn { font-size: 12px; padding: 0 2px; }
.ppm-table tr.ppm-shelf-changed .ppm-shelf input { border-color: var(--blue); }
.promo-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.promo-filters select, .promo-filters input { width: auto; flex: 1 1 180px; margin: 0; }
.promo-tab-off { opacity: .55; cursor: default; }
.promo-row .sub { white-space: normal; }
.promo-hint { font-size: 12px; margin-top: 2px; }
.promo-err { white-space: pre-line; }
.promo-prod-list { max-height: 50vh; overflow: auto; border: 1px solid var(--line, #e5e1d8); border-radius: 8px; padding: 4px 8px; margin-top: 6px; }
.promo-prod { margin: 4px 0; }
.mc-setmonth { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.mc-setmonth input { width: auto; margin: 0; }
.ci-chk-bad td { background: #fff4f2; }
.ci-chk-sub { font-size: 11px; }
.shelf-eff { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.shelf-eff input { width: auto; margin: 0; }
.no-consign .ppm-consign-col, .no-sell .ppm-off { display: none; }
@media (max-width: 600px) {
  .pe-grid { grid-template-columns: 1fr; }
  .ppm-table .ppm-chk { width: 56px; }
  .ppm-table .ppm-price { width: 96px; }
  .ppm-table .ppm-shelf { width: 110px; }
}
/* สินค้า: ติ๊ก "ขายอยู่" แทนปุ่มยกเลิกขาย */
.active-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-weight: normal; cursor: pointer; white-space: nowrap; }
.active-toggle input { width: 20px; height: 20px; margin: 0; }
/* หน้าแก้ไขรายการของฉัน: กล่องรายการเดิม */
.my-edit-orig { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 4px 0 12px; }
.my-edit-orig .main { font-weight: 600; margin-top: 2px; }
.my-edit-orig .sub { font-size: 13px; color: var(--gray); margin-top: 2px; }
/* รายงานชุดที่ 2 */
.pos-num { color: var(--green); }
.w-80 { width: 80px !important; display: inline-block; margin: 0 4px; }
.inline-label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: normal; }
tr.group-row td { background: var(--green-light); }
/* สิทธิ์ผู้ใช้แบ่งหมวด */
.perm-groups { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 12px; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.perm-group > summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; font-weight: 600; list-style: none; }
.perm-group > summary::-webkit-details-marker { display: none; }
.perm-group > summary::after { content: "▸"; margin-left: 4px; color: var(--gray); }
.perm-group[open] > summary::after { content: "▾"; }
.perm-group > summary .perm-group-name { flex: 1; }
.perm-group > summary input { width: 20px; height: 20px; margin: 0; }
.perm-group .checkbox-list { padding: 0 12px 10px 42px; }
.rep-vis-group { margin-bottom: 12px; }
.rep-vis-title { font-weight: 600; margin: 6px 0 2px; }
.mt-12 { margin-top: 12px; }
/* 1 บัญชี = 1 เครื่อง */
.session-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 10px 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.login-note { font-size: 12px; margin-top: 10px; text-align: center; }

/* Face ID / passkey (v26) */
a.user-chip { color: inherit; text-decoration: none; cursor: pointer; }
.pk-login-btn { width: 100%; margin: 8px 0 4px; }
.pk-or { text-align: center; font-size: 12px; margin: 6px 0 2px; }
.pk-offer { border: 1px solid var(--accent-gold); }
.pk-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pk-hint { font-size: 12px; margin: 8px 0 4px; text-align: center; }
/* checkbox/radio ไม่ยืดเต็มความกว้าง (กฎ input { width:100% } ทำให้ข้อความถูกดันตกขอบบน iPhone — เจ้าของระบบ 2026-10-06) */
input:where([type="checkbox"], [type="radio"]) { width: auto; flex: 0 0 auto; padding: 0; }
.pe-check > span { min-width: 0; flex: 1 1 auto; }
.pk-diag { font-size: 11px; margin-top: 6px; }

/* คู่มือการใช้งาน (#/help) */
.topbar .help-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 999px;
  background: rgba(255,255,255,0.14); text-decoration: none; font-size: 17px; flex: 0 0 auto; }
.manual .man-body { line-height: 1.75; }
.manual .man-body p { margin: 8px 0; }
.manual .man-h { margin: 18px 0 6px; color: var(--green-dark); }
.manual h2.man-h { font-size: 19px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.manual h3.man-h { font-size: 16px; }
.manual h4.man-h { font-size: 15px; }
.manual .man-list { margin: 6px 0 10px; padding-left: 22px; }
.manual .man-list li { margin: 4px 0; }
.manual .man-sub { margin: 2px 0 0 4px; font-size: 14px; }
.manual .man-note { margin: 10px 0; }
.manual code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.manual .man-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.manual .man-table th, .manual .man-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.manual .man-table th { background: rgba(0,0,0,0.04); }
.manual .man-live { margin: 8px 0; }
.manual .man-live ul { margin: 4px 0; padding-left: 22px; }
.manual .man-live-title { font-weight: 600; margin-top: 8px; }
.manual .man-updated { font-size: 12px; margin-bottom: 6px; }
.manual .man-nav { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.manual .man-search input { width: 100%; }
.manual .man-group { margin-top: 14px; }
.manual .man-group-title { font-weight: 700; margin-bottom: 4px; }
.manual .man-toc-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 8px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.manual .man-toc-item > span:first-child { font-size: 18px; }
.manual .man-snippet { font-size: 12px; margin-top: 2px; }

/* ป้าย รวม/ไม่รวมฝากขาย ข้างชื่อรายงาน */
.scope-chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; white-space: nowrap; }
.scope-incl { background: #e3f2e7; color: #1d6b3a; }
.scope-excl { background: #eceae4; color: #5b5648; }
.scope-only { background: #fff1d6; color: #8a5a00; }
.scope-na { background: #eef2f7; color: #4a5a70; }
/* สถานะเชิงลบ (ยกเลิก / ถูกปฏิเสธ / ยอดไม่ตรง / เกินกำหนด) — แดงชัดเจน */
.scope-bad { background: #fde2e1; color: #b42318; }

/* นำเข้าไฟล์ตัดขายฝากขาย + รายงานตัดขาย */
td.num, th.num { text-align: right; white-space: nowrap; }
.ci-row { display: block; text-decoration: none; color: inherit; }
.ci-price { width: 120px; text-align: right; }
.cs-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.cs-tabs button { padding: 6px 12px; font-size: 13px; width: auto; flex: 0 0 auto; }
.ci-format summary { cursor: pointer; }

/* งานค้างที่ต้องตรวจ: ปุ่มหัวการ์ดเรียงแนวนอน */
.hdr-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hdr-actions > *, .hdr-actions > button.primary, .hdr-actions > a.secondary { width: auto; flex: 0 0 auto; margin: 0; }

/* เช็คยอดบิล: หมายเหตุสินค้าที่ยังไม่มีราคา — ตัวเล็ก จาง ตัดบรรทัดได้ */
td.pc-note { font-size: 12px; color: var(--muted, #888); min-width: 220px; white-space: normal; }

/* งานค้าง: แถวบิลกดเข้าไปดูรายละเอียดได้ */
a.pc-link { display: block; flex: 1; color: inherit; text-decoration: none; }
a.pc-link:hover .main { text-decoration: underline; }
.text-warn { color: var(--yellow, #b7791f); }
.text-ok { color: var(--green, #2f855a); }
/* ฟอร์มโปร: ช่องตัวเลขในประโยค */
.promo-sentence { font-size: 17px; line-height: 2.4; }
.promo-sentence .promo-num { display: inline-block; width: 90px; margin: 0 6px; text-align: center; }

/* ยอดขายรายบิล: หัวคอลัมน์กดเรียง / แถวกดดูบิล */
th.sb-sort { cursor: pointer; user-select: none; white-space: nowrap; }
tr.sb-row { cursor: pointer; }
tr.sb-row:hover td { background: var(--hover, rgba(0,0,0,0.03)); }
.hidden { display: none !important; }
/* ลิงก์ที่ทำหน้าที่เป็นปุ่มหลัก (เช่น แถบที่เลือกอยู่) */
a.primary { background: var(--green); color: #fff; border: 1px solid var(--green); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; text-decoration: none; display: inline-block; white-space: nowrap; }
.cs-tabs a { width: auto; flex: 0 0 auto; }

/* แถวคั่นวัสดุ + ยอดรวมย่อย (เจ้าของระบบ 2026-10-15) */
tr.mat-sep td { background: #f3ede0; border-top: 2px solid var(--border); }
tr.subtotal-row td { background: #faf6ec; font-size: 13px; }

/* ส่วนลดท้ายบิลตามเงื่อนไขลูกค้า (เจ้าของระบบ 2026-10-16) */
.deduct-info { margin: 12px 0 4px; padding: 8px 12px; background: var(--yellow-light); border-radius: var(--radius-sm); font-size: 13px; }
.ed-row { margin-bottom: 6px; }
.ed-pct-wrap { display: flex; gap: 6px; align-items: center; }
.ed-pct-wrap input { flex: 1 1 auto; }
.ed-pct-wrap button { flex: 0 0 auto; width: auto; padding: 8px 12px; }

/* ที่มาของตัวเลขในหน้าเช็คยอดบิล: ✍️ ผู้คีย์กรอก / 🧮 ระบบคำนวณ / 🔒 ตั้งไว้ในระบบ (เจ้าของระบบ 2026-10-16) */
.src-legend { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.src-tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.src-user { background: #e3eefb; color: #1f5fa8; }
.src-sys { background: #eee8d8; color: #5a5446; }
.src-set { background: #efe6f6; color: #6b3f93; }
.src-user-txt { color: #1f5fa8; font-weight: 600; }
table.pc-sum tr.row-user td { color: #1f5fa8; }
table.pc-sum tr.row-key td { background: #f6f1e4; }
.pc-how { font-size: 11.5px; color: var(--gray); margin-top: 2px; font-weight: normal; }

/* ---- ใบสั่งซื้อ (PO) — migrate_v37 ---- */
.po-lines select { min-width: 220px; }
.po-row { align-items: flex-start; }
.po-row-main { flex: 1 1 auto; min-width: 0; }
.po-row-acts { flex-wrap: wrap; justify-content: flex-end; }
.po-lines input { margin: 0; max-width: 130px; }
.po-totals { font-size: 14px; }
.po-pick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.po-pick select { flex: 1 1 260px; margin: 0; }
.po-doc { background: #fff; color: #111; padding: 24px; font-size: 13px; line-height: 1.45; }
.po-doc-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #222; padding-bottom: 10px; }
.po-doc-coname { font-size: 18px; font-weight: 700; }
.po-doc-title { text-align: right; font-size: 22px; font-weight: 700; }
.po-doc-small { font-size: 12px; font-weight: 400; }
.po-doc-sku { color: #555; font-size: 11px; }
.po-pre { white-space: pre-line; }
.po-doc-meta { display: flex; justify-content: space-between; gap: 16px; margin: 12px 0; }
.po-doc-right { text-align: right; }
.po-doc-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.po-doc-table th, .po-doc-table td { border: 1px solid #999; padding: 4px 6px; }
.po-doc-table th { background: #f0f0f0; }
.po-doc-table th:nth-child(2), .po-doc-table td:nth-child(2) { text-align: left; }
.po-doc-sum { margin-left: auto; width: 320px; max-width: 100%; }
.po-doc-sum > div { display: flex; justify-content: space-between; padding: 2px 0; }
.po-doc-grand { font-weight: 700; border-top: 1px solid #222; border-bottom: 3px double #222; }
.po-doc-sign { display: flex; justify-content: space-around; text-align: center; margin-top: 48px; }
@media print {
  .topbar, .bottomnav, .no-print, .help-btn { display: none !important; }
  body, .content { background: #fff !important; padding: 0 !important; margin: 0 !important; }
  .po-doc-card { box-shadow: none !important; border: none !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .po-doc { padding: 0; }
}

/* รายงานกำไรขั้นต้น: ขั้นการคำนวณ (migrate_v40) */
.gp-steps { display: grid; gap: 4px; max-width: 640px; margin: 8px 0; }
.gp-steps > div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.gp-steps > div b { text-align: right; white-space: nowrap; }
.gp-steps .gp-sub, .gp-steps .gp-total { border-top: 1px solid var(--border, #ddd); padding-top: 4px; }
.gp-steps .gp-total { font-size: 1.05em; }
.mct-box summary { cursor: pointer; }

/* ตัวเลขที่ดูวิธีคำนวณได้ (calcTip) — เส้นประใต้ตัวเลข · บับเบิลลอยตามจอ (position: fixed — ไม่ถูกตัดในตาราง) */
.calc-tip { border-bottom: 1px dotted currentColor; cursor: help; position: relative; }
.calc-tip .calc-bubble { display: none; position: fixed; left: 0; top: 0; z-index: 60; width: max-content; max-width: min(90vw, 380px);
  background: #2b2f26; color: #fff; font-size: 12px; font-weight: 400; line-height: 1.55; padding: 8px 10px; border-radius: 8px;
  text-align: left; white-space: normal; box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.calc-tip .calc-bubble b { font-weight: 700; color: #fff; }
.calc-tip .calc-bubble::before { display: none; }
.calc-tip .calc-bubble div { margin-top: 2px; }
.calc-tip.open .calc-bubble { display: block; }
/* แถบปุ่มเรียงรายการในหน้าตั้งค่า (สินค้า/Supplier/ลูกค้า) */
.ml-sort { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.ml-sort button { width: auto; flex: 0 0 auto; padding: 4px 12px; font-size: 13px; }
