/* ============================================================
   BHP — สไตล์กลางทุกแอปใต้ /app/   (UTF-8)
   รุ่น 2.5 — 11 ต.ค. 2569
   - ปุ่ม/ช่องกรอกใหญ่ กดง่ายบนมือถือ (สูงขั้นต่ำ 48px)
   - ตั้งค่าการพิมพ์ (ใช้คู่กับ ui.js)
   - หน้าดูรูป/ไฟล์แนบ (ใช้คู่กับ ui.js)
   - ช่องเลือกแบบพิมพ์ได้ <select class="js-search"> + ค้นหาในตาราง <table class="js-filter"> (ใช้คู่กับ ui.js)
   - ป้ายสถานะ .tag.ok/.warn/.bad · หน้าต่างเลื่อนขึ้น .sheet (รุ่น 2.5)
   ============================================================ */

:root {
  --paper: #F3F5F6;   /* พื้นคอนกรีตอ่อน */
  --card:  #FFFFFF;
  --ink:   #1C2730;
  --steel: #4A6272;
  --line:  #D3DAE0;
  --field: #B8C3CB;   /* ขอบช่องกรอก */
  --hivis: #F2B705;   /* เหลืองเซฟตี้ ใช้เฉพาะจุดสำคัญ */
  --ok:    #2F7D4F;
  --bad:   #B42318;
  --lead:  #2F5E8C;
  --tap:   48px;      /* ความสูงขั้นต่ำของปุ่ม/ช่องกรอก */
  --tap-sm: 40px;     /* ปุ่มเล็กในตาราง */
  --pf:    8.5pt;     /* ขนาดตัวอักษรตอนพิมพ์ (ui.js ปรับให้) */
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
details * { box-sizing: border-box; }   /* กันช่องกรอกในกล่องพับล้น */

body { margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.6 "IBM Plex Sans Thai", Tahoma, "Leelawadee UI", sans-serif; }
a { color: var(--lead); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 .6rem; }
small, .muted { color: var(--steel); }
summary { cursor: pointer; min-height: var(--tap-sm); display: list-item; }

/* ---------- แถบบน ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .6rem 1rem; background: var(--ink); color: #fff;
  border-bottom: 5px solid var(--hivis); }
.bar a { color: #fff; text-decoration: none; }
.bar .home { display: grid; place-items: center; width: var(--tap); height: var(--tap);
  border-radius: 6px; background: #2c3a45; flex-shrink: 0; }
.bar .home:hover { background: #3a4a56; }
.bar .app-name { font-weight: 600; margin-right: auto; }
.bar .who { margin-left: auto; display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9rem; align-items: center; }
.bar .who small { color: #b9c5cd; }
.bar .who a { opacity: .85; display: inline-flex; align-items: center; min-height: 40px; }
.bar .who a:hover { opacity: 1; text-decoration: underline; }

/* ---------- โครงหน้า ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: .75rem; margin-bottom: 1rem; min-width: 0; }
.head > div { min-width: 0; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.flash { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border-left: 5px solid var(--ok); background: #E8F3EC; }
.flash.bad  { border-color: var(--bad);   background: #FBEAE8; }
.flash.warn { border-color: var(--hivis); background: #FFF6D6; }

/* กันข้อความยาวล้นกรอบ */
.panel, .stats, td, th, .chip, .tag, .flash, summary { overflow-wrap: anywhere; }

/* ---------- ตัวเลขสรุป ---------- */
.stats { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; background: var(--card); margin-bottom: 1rem; }
.stats div { flex: 1 1 140px; padding: .8rem 1rem; border-right: 1px solid var(--line); }
.stats div:last-child { border-right: 0; }
.stats b { display: block; font-size: 1.7rem; line-height: 1.1; }

/* ---------- ฟอร์ม ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: .9rem 1rem; align-items: end; }
.grid > label { min-width: 0; }

label { display: block; min-width: 0; max-width: 100%; font-size: .88rem; color: var(--steel); }

input, select, textarea { display: block; width: 100%; max-width: 100%; min-width: 0; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=tel],
input[type=search], input[type=date], input[type=time], input[type=month], select, textarea {
  min-height: var(--tap); margin-top: .2rem; padding: .55rem .75rem;
  font: inherit; font-size: 16px;            /* 16px = iPhone ไม่ซูมเองตอนแตะ */
  color: var(--ink); border: 1px solid var(--field); border-radius: 6px; background: #fff; }
select { text-overflow: ellipsis; }
textarea { min-height: 96px; resize: vertical; }

input[type=checkbox], input[type=radio] { display: inline-block; width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--ink); }
input[type=range] { min-height: var(--tap-sm); accent-color: var(--ink); }

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--hivis); outline-offset: 1px; }

/* ตัวเลือกแบบเม็ด (pill) */
.choice { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .3rem; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--field); border-radius: 999px; background: #fff; cursor: pointer; color: var(--ink); }
.choice input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.choice input:focus-visible + span { outline: 3px solid var(--hivis); }

/* กล่องติ๊ก */
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: .5rem; margin-top: .4rem; }
.checks label { display: flex; gap: .6rem; align-items: center; min-width: 0; min-height: var(--tap);
  color: var(--ink); font-size: .95rem; padding: .45rem .7rem;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.checks label span { min-width: 0; overflow-wrap: anywhere; }

.inline-add { align-items: end; }
.inline-add > label { flex: 1 1 200px; min-width: 0; }

/* ช่องรหัสผ่าน + ปุ่มรูปตา (layout.php ใส่ให้อัตโนมัติ) */
.pw { position: relative; display: block; }
.pw input { padding-right: var(--tap); }
.pw-eye { position: absolute; right: 0; top: .2rem; bottom: 0; width: var(--tap); display: grid; place-items: center;
  border: 0; background: transparent; color: var(--steel); cursor: pointer; padding: 0; }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: var(--tap); padding: 0 1.1rem; font: inherit; font-size: 1rem; font-weight: 600;
  border-radius: 6px; cursor: pointer; border: 1px solid var(--ink); background: #fff; color: var(--ink);
  text-decoration: none; -webkit-tap-highlight-color: transparent; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--hivis); border-color: #c99700; }
.btn.danger  { border-color: var(--bad); color: var(--bad); }
.btn.small   { min-height: var(--tap-sm); padding: 0 .8rem; font-size: .9rem; font-weight: 500; }
.btn.block   { display: flex; width: 100%; }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; align-items: center; }
.actions > * { min-width: 0; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

/* ปุ่มพิมพ์บนแถบบน */
.bar .js-print { background: transparent; color: #fff; border-color: #6b7f8c; }
.bar .js-print:hover { background: #2c3a45; }

/* ---------- ตาราง ---------- */
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; line-height: 1.45; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { background: #E7ECEF; font-weight: 600; font-size: .78rem; color: var(--steel); }
td.wrap { white-space: normal; min-width: 110px; }
tbody tr:last-child td { border-bottom: 0; }
tr.off td { color: #8a979f; }
.num { text-align: right; }
@media (max-width: 1000px) {
  table { font-size: .8rem; }
  th, td { padding: .4rem .45rem; }
  th { font-size: .74rem; }
}

/* ---------- ป้ายสถานะ ---------- */
.tag { display: inline-block; padding: 0 .4rem; border-radius: 4px; font-size: .76rem; line-height: 1.55; background: #E7ECEF; white-space: nowrap; }
.tag.admin  { background: var(--ink); color: #fff; }
.tag.lead   { background: #DCE8F4; color: var(--lead); }
.tag.proj   { background: #FFF1C2; color: #6b5200; }
.tag.appadm { background: #FFE7A3; color: #5c4500; }
.tag.closed { background: #eee; color: #777; }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login { max-width: 380px; margin: 8vh auto 0; }
.login h1 { border-left: 6px solid var(--hivis); padding-left: .6rem; }

@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .bar .app-name { border: 0; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ============================================================
   ช่องเลือกแบบพิมพ์ได้ (Combobox)  <select class="js-search">
   ============================================================ */
.ss { position: relative; margin-top: .2rem; }
.ss-native { position: absolute !important; left: 0; bottom: 0; width: 1px !important; height: 1px !important;
  min-height: 0 !important; opacity: 0; pointer-events: none; }
.ss-box { position: relative; }
.ss-box .ss-in { margin-top: 0; padding-right: 88px; text-overflow: ellipsis; cursor: text; }
.ss-box .ss-in::placeholder { color: #8a979f; opacity: 1; }
.ss-arw, .ss-clr { position: absolute; top: 0; bottom: 0; width: 44px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--steel); cursor: pointer; padding: 0; }
.ss-arw { right: 0; } .ss-clr { right: 40px; }
.ss-arw svg, .ss-clr svg { width: 20px; height: 20px; }
.ss-clr svg { width: 18px; height: 18px; }
.ss.open .ss-arw svg { transform: rotate(180deg); }
.ss.open .ss-in { border-color: var(--ink); border-radius: 6px 6px 0 0; }
.ss-dd { position: absolute; z-index: 50; left: 0; right: 0; top: 100%; background: #fff;
  border: 1px solid var(--ink); border-top: 0; border-radius: 0 0 6px 6px; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.ss-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; }
.ss-list li { display: flex; align-items: center; min-height: 46px; padding: .4rem .75rem;
  border-bottom: 1px solid #eef1f3; color: var(--ink); cursor: pointer; overflow-wrap: anywhere; }
.ss-list li:hover, .ss-list li.hl { background: #FFF6D6; }
.ss-list li.sel { font-weight: 600; }
.ss-list li.ss-none { color: var(--steel); cursor: default; background: none; }

/* ช่องค้นหาในตาราง  <table class="js-filter"> */
.tf { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .75rem; margin-bottom: .5rem; }
.tf-box { position: relative; flex: 1 1 240px; max-width: 420px; }
.tf-box > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--steel); pointer-events: none; }
.tf-box .tf-in { margin: 0; padding-left: 40px; padding-right: 44px; }
.tf-box .tf-in::-webkit-search-cancel-button { display: none; }
.tf-clr { position: absolute; right: 0; top: 0; bottom: 0; width: 44px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--steel); cursor: pointer; }
.tf-clr svg { width: 18px; height: 18px; }
.tf-cnt { font-size: .85rem; }
.ss-clr[hidden], .tf-clr[hidden] { display: none; }
tr.tf-none td { text-align: center; color: var(--steel); padding: 1rem; white-space: normal; }

/* ============================================================
   แผงตั้งค่าการพิมพ์  (ui.js สร้างให้)
   ============================================================ */
.pp-back { position: fixed; inset: 0; z-index: 900; background: rgba(28,39,48,.55);
  display: flex; align-items: flex-end; justify-content: center; }
.pp-box { width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; background: #fff;
  border-radius: 12px 12px 0 0; padding: 0 1rem 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 600px) { .pp-back { align-items: center; } .pp-box { border-radius: 12px; } }
.pp-top { position: sticky; top: 0; display: flex; align-items: center; gap: .5rem; padding: .75rem 0;
  background: #fff; border-bottom: 1px solid var(--line); margin-bottom: .5rem; }
.pp-top b { flex: 1; font-size: 1.1rem; }
.pp-lb { font-size: .88rem; color: var(--steel); margin: .8rem 0 .3rem; }
.pp-row { display: flex; align-items: center; gap: .75rem; }
.pp-row input[type=range] { flex: 1; }
.pp-val { min-width: 4.2em; text-align: right; font-weight: 600; }
.pp-chk { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); color: var(--ink); font-size: .95rem; }
.pp-prev { display: flex; justify-content: center; align-items: center; height: 220px; margin-top: .8rem;
  background: #E7ECEF; border-radius: 6px; }
.pp-page { background: #fff; border: 1px solid #999; transition: all .15s; }
.pp-area { height: 100%; border: 1px dashed var(--hivis); overflow: hidden; color: var(--ink); line-height: 1.5; }
.pp-area div:first-child { background: #eee; color: var(--steel); }
.pp-size { text-align: center; font-size: .82rem; color: var(--steel); margin-top: .3rem; }

/* ปุ่มไอคอนกลม (ใช้ทั้งแผงพิมพ์และหน้าดูรูป) */
.icon-btn { display: grid; place-items: center; width: var(--tap); height: var(--tap); flex-shrink: 0;
  border-radius: 50%; border: 0; background: #E7ECEF; color: var(--ink); cursor: pointer; text-decoration: none; }
.icon-btn svg { width: 24px; height: 24px; }

/* ============================================================
   หน้าดูรูป/ไฟล์แนบ  (ui.js สร้างให้)
   ============================================================ */
.vw { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column;
  background: #111; color: #fff; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.vw[hidden] { display: none; }
.vw-top, .vw-bot { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; }
.vw-title { flex: 1; min-width: 0; font-size: .9rem; color: #ccc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vw .icon-btn { background: #2c3a45; color: #fff; }
.vw .icon-btn.vw-dl { background: var(--hivis); color: var(--ink); }
.vw-stage { position: relative; flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none; }
.vw-stage img { max-width: 100%; max-height: 100%; transform-origin: center; will-change: transform; -webkit-user-drag: none; }
.vw-file { text-align: center; padding: 1rem; }
.vw-file svg { width: 72px; height: 72px; color: #9aa9b3; }
.vw-file p { margin: .5rem 0 1rem; overflow-wrap: anywhere; }
.vw-file .btn { color: var(--ink); }
.vw-nav { position: absolute; top: 50%; transform: translateY(-50%); }
.vw-prev { left: .5rem; } .vw-next { right: .5rem; }
.vw-bot input[type=range] { flex: 1; }
.vw-pct { min-width: 3.5em; text-align: right; font-size: .9rem; }
.vw-bot svg { width: 22px; height: 22px; flex-shrink: 0; color: #ccc; }
.vw-note { padding: .5rem .8rem; font-size: .82rem; color: #ddd; background: #2c3a45; text-align: center; }
.vw-note.warn { background: #5c4500; color: #fff; }
.vw-note[hidden] { display: none; }

/* ============================================================
   Collapsible Sidebar — เมนูซ้าย (ย่อเป็น Navigation rail) / เนื้อหาขวา  (nav.php)
   ============================================================ */
main:has(> .app-shell) { max-width: none; padding: 0; }
.app-shell { display: flex; align-items: stretch; min-height: calc(100vh - 66px); }
.app-nav { width: 230px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line);
  overflow: hidden; transition: width .2s; }
.app-shell.mini .app-nav { width: 60px; }
.app-main { flex: 1; min-width: 0; padding: 1rem; max-width: 1100px; }
.nav-gp { display: flex; align-items: center; min-height: 36px; padding: 0 14px; background: #E7ECEF;
  color: var(--steel); font-size: .82rem; font-weight: 600; white-space: nowrap; }
.nav-it { position: relative; display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 0 14px; border-bottom: 1px solid #eef1f3; border-left: 4px solid transparent;
  color: var(--ink); text-decoration: none; white-space: nowrap; font-size: .95rem; }
.nav-it svg { width: 22px; height: 22px; flex-shrink: 0; color: var(--steel); }
.nav-it:hover { background: #F7F9FA; }
.nav-it.on { background: #FFF6D6; border-left-color: var(--hivis); font-weight: 600; }
.nav-it.on svg { color: var(--ink); }
.nav-tx { overflow: hidden; text-overflow: ellipsis; }
.nav-badge { margin-left: auto; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--bad);
  color: #fff; font-size: .75rem; line-height: 20px; text-align: center; font-weight: 600; }
/* แบบย่อ: เหลือไอคอน กลุ่มเหลือเส้นคั่น ตัวเลขแจ้งเตือนเป็นจุดบนไอคอน */
.app-shell.mini .nav-tx { display: none; }
.app-shell.mini .nav-gp { min-height: 8px; padding: 0; }
.app-shell.mini .nav-it { justify-content: center; padding: 0; gap: 0; }
.app-shell.mini .nav-badge { position: absolute; top: 6px; right: 8px; min-width: 10px; height: 10px; padding: 0; font-size: 0; }
/* ปุ่ม ≡ บนแถบบน (ui.js ใส่ให้) */
.bar .nav-toggle { display: grid; place-items: center; width: var(--tap); height: var(--tap); flex-shrink: 0; padding: 0;
  border-radius: 6px; border: 1px solid #6b7f8c; background: transparent; color: #fff; cursor: pointer; }
.bar .nav-toggle svg { width: 24px; height: 24px; }
.bar .nav-toggle:hover { background: #2c3a45; }
@media (max-width: 600px) {
  .app-nav { width: 184px; }
  .nav-it { font-size: .9rem; gap: 10px; padding: 0 10px; }
  .app-main { padding: .75rem; }
}

/* ============================================================
   หน้า "ภาพรวม" (overview.php) — ตัวเลขสรุป + กราฟเลือกชนิดได้
   ============================================================ */
.ov-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: .6rem; margin-bottom: 1rem; }
@media (max-width: 600px) { .ov-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ov-kpi { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  padding: .7rem .85rem; color: var(--ink); text-decoration: none; min-width: 0; }
a.ov-kpi:hover { border-color: var(--steel); }
.ov-kpi span { display: block; font-size: .82rem; color: var(--steel); overflow-wrap: anywhere; }
.ov-kpi b { display: block; font-size: 1.6rem; line-height: 1.2; font-weight: 600; }
.ov-kpi b small { font-size: .8rem; font-weight: 400; color: var(--steel); }
.ov-kpi.warn { border-left: 5px solid var(--bad); }
.ov-kpi.warn b { color: var(--bad); }
.ov-seg { display: flex; border: 1px solid var(--field); border-radius: 6px; overflow: hidden; margin-bottom: .4rem; }
.ov-seg button { flex: 1; min-height: 44px; border: 0; border-right: 1px solid var(--field); background: #fff;
  color: var(--ink); font: inherit; font-size: .92rem; cursor: pointer; }
.ov-seg button:last-child { border-right: 0; }
.ov-seg button.on { background: var(--ink); color: #fff; font-weight: 600; }
.ov-seg button:disabled { background: #F3F5F6; color: #b8c3cb; cursor: not-allowed; }
.ov-hint { font-size: .8rem; min-height: 1.2em; margin-bottom: .4rem; }
.ov-canvas { position: relative; height: 300px; }
@media (max-width: 600px) { .ov-canvas { height: 260px; } }
/* ตารางติ๊กสิทธิ์ */
.ov-perm { table-layout: fixed; }
.ov-perm th { white-space: normal; vertical-align: bottom; line-height: 1.3; }
.ov-perm th:first-child { width: 38%; }
.ov-perm td { padding-top: .25rem; padding-bottom: .25rem; }
.ov-perm th.c, .ov-perm td.c { text-align: center; padding-left: 2px; padding-right: 2px; }
.ov-perm tr.ov-sec td { background: #F3F5F6; color: var(--steel); font-weight: 600; font-size: .8rem; }
.ov-tick { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 40px; cursor: pointer; }
.nav-gp.blank { min-height: 6px; padding: 0; }

/* ============================================================
   เอกสารพิมพ์ (company.php) — หัวกระดาษ / ช่องลงนาม / ตราประทับ
   ============================================================ */
.doc-paper { position: relative; background: #fff; color: #111; border: 1px solid var(--line); border-radius: 6px;
  padding: 1.25rem; margin-bottom: 1rem; overflow: hidden; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem 1.25rem;
  padding-bottom: .6rem; border-bottom: 1px solid #ccc; margin-bottom: .9rem; }
.doc-brand { min-width: 0; }
.doc-logo { display: block; height: 64px; max-width: 100%; }
.doc-addr { margin-top: .35rem; font-size: .76rem; color: #333; line-height: 1.45; }
.doc-title { text-align: right; flex-shrink: 0; margin-right: calc(2rem + 1cm); }   /* ขยับชื่อเอกสารเข้ามาจากขอบขวา */
.doc-title h1 { font-size: 1.35rem; line-height: 1.25; margin: .1rem 0 .25rem; }
.doc-title div { font-size: .85rem; color: #333; line-height: 1.5; }
.doc-paper table { border: 1px solid #bbb; }
.doc-signs { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 1rem; margin-top: 2rem;
  text-align: center; font-size: .85rem; break-inside: avoid; page-break-inside: avoid; }
.doc-sign-area { position: relative; height: 78px; margin: 0 .5rem .2rem; border-bottom: 1px dotted #555; }
.doc-sig { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); max-height: 70px; max-width: 90%; }
.doc-stamp { position: absolute; right: 2%; top: -14px; height: 96px; max-width: 45%; object-fit: contain; opacity: .88;
  mix-blend-mode: multiply; }
.doc-sign-name { margin-top: .15rem; }
.doc-watermark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 5rem; font-weight: 700; color: rgba(180,35,24,.08); transform: rotate(-20deg); }
@media (max-width: 600px) {
  .doc-paper { padding: .75rem; }
  .doc-logo { height: 44px; }
  .doc-head { flex-wrap: wrap; }
  .doc-title { text-align: left; width: 100%; margin-right: 0; }
  .doc-signs { grid-template-columns: 1fr 1fr; }
}
/* อัปโหลดตรา/ลายเซ็น: พื้นลายตาราง = ส่วนโปร่งใส */
.pc-view { display: inline-block; max-width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 6px;
  background: repeating-conic-gradient(#e6eaed 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.pc-view canvas { display: block; max-width: 100%; max-height: 260px; }
.pc { margin-top: .6rem; }
input[type=file] { margin-top: .3rem; font: inherit; font-size: .95rem; color: var(--ink); }
input[type=file]::file-selector-button { min-height: var(--tap); padding: 0 1rem; margin-right: .75rem; font: inherit; font-weight: 600;
  border: 1px solid var(--ink); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
.pc-row { display: flex; align-items: center; gap: .6rem; margin-top: .5rem; color: var(--ink); }
.pc-row input { flex: 1; }
.pc-chk { display: flex; align-items: center; gap: .5rem; min-height: 44px; color: var(--ink); }

/* ============================================================
   การพิมพ์ — ค่าจริงของ @page ui.js ใส่ให้ตามที่ผู้ใช้ตั้ง
   ============================================================ */
@page { size: A4 landscape; margin: 10mm; }
@media print {
  html, body { width: auto; background: #fff; margin: 0; padding: 0; }
  main { max-width: none; padding: 0; }
  .bar, .noprint, .actions, details.panel, dialog, .login, .pp-back, .vw, .js-print, .app-nav { display: none !important; }
  .app-shell { display: block; min-height: 0; }
  .doc-paper { border: 0; padding: 0; margin: 0; border-radius: 0; overflow: visible; }
  .doc-logo { height: 52px; }
  .doc-addr { font-size: 7.5pt; }
  .doc-head { flex-wrap: nowrap; }
  .doc-title { text-align: right; width: auto; margin-right: 20mm; }
  .doc-title h1 { font-size: calc(var(--pf) + 5pt); }
  .doc-signs { font-size: var(--pf); }
  .doc-head, .doc-sig, .doc-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ov-seg, .ov-hint, .ov-chart .grid { display: none !important; }
  .ov-kpis { grid-template-columns: repeat(4, 1fr); }
  .ov-kpi { border-color: #999; }
  .app-main { padding: 0; max-width: none; }
  h1 { font-size: calc(var(--pf) + 6.5pt); }
  h2 { font-size: calc(var(--pf) + 2.5pt); margin: 8pt 0 3pt; break-after: avoid; page-break-after: avoid; }
  .head { margin-bottom: 6pt; }
  .muted, small { font-size: calc(var(--pf) - .5pt); }
  .panel { border: 0; padding: 0; }
  .stats { border-color: #999; margin-bottom: 6pt; }
  .stats div { padding: 3pt 6pt; border-color: #999; }
  .stats b { font-size: calc(var(--pf) + 3.5pt); }
  .scroll { overflow: visible !important; border: 0; }
  table { width: 100%; table-layout: fixed; font-size: var(--pf); border: 1px solid #999; }
  th, td { padding: 2pt 3pt; white-space: normal; overflow-wrap: anywhere; border-color: #bbb; }
  th { background: #eee; font-size: calc(var(--pf) - .5pt); }
  thead { display: table-header-group; }   /* หัวตารางซ้ำทุกหน้า */
  tfoot { display: table-footer-group; }
  tr { break-inside: avoid; page-break-inside: avoid; }
  .tag { border: 1px solid #ccc; background: #fff !important; color: #000 !important; padding: 0 2pt; }
  a { color: #000; text-decoration: none; }

  /* ปิด "จัดให้พอดีหน้า" = ตารางกว้างตามเนื้อหา */
  html.pp-nofit table { table-layout: auto; }
  html.pp-nofit th, html.pp-nofit td { white-space: nowrap; }
}

/* ============================================================
   รุ่น 2.5 — ป้ายสถานะ, ติ๊กแบบแน่น, หน้าต่างเลื่อนขึ้น (Bottom sheet)
   ============================================================ */
/* ป้ายสถานะ: <span class="tag ok|warn|bad">  (เขียว/เหลือง/แดง) */
.tag.ok   { background: #E8F3EC; color: #1e6b3a; font-weight: 600; }
.tag.warn { background: #FFF1C2; color: #6b5200; font-weight: 600; }
.tag.bad  { background: #FBEAE8; color: var(--bad); font-weight: 600; }
tr.row-bad td { background: #FFF8F7; }

/* ติ๊กในตาราง: <div class="checks tight"> */
.checks.tight { display: flex; flex-wrap: wrap; margin: 0; }
.checks.tight label { min-height: var(--tap-sm); padding: 0 .6rem; }

/* Bottom sheet — มือถือเลื่อนขึ้นจากล่าง, จอใหญ่อยู่กลางจอ
   <div class="sheet" hidden><div class="sheet-box"><div class="sheet-head"><b>หัวข้อ</b><button class="icon-btn sheet-x">×</button></div> ... </div></div> */
.sheet { position: fixed; inset: 0; z-index: 900; background: rgba(15, 22, 28, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-box { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 14px 14px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); }
.sheet-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.sheet-head b { flex: 1; min-width: 0; font-size: 1.1rem; }
.sheet-x { border-radius: 50%; border: 0; background: #E7ECEF; color: var(--ink); }
.sheet-x svg { width: 22px; height: 22px; }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-box { border-radius: 14px; } }

/* ตัวอย่างลายน้ำ */
.wm-prev { margin: .6rem 0 .3rem; border: 1px solid var(--line); border-radius: 6px; background: #EEF1F3;
  display: flex; justify-content: center; align-items: center; height: 240px; overflow: hidden; }
.wm-prev canvas { max-width: 100%; max-height: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.18); background: #fff; }
.wm-busy { display: flex; align-items: center; gap: .5rem; }
.wm-busy::before { content: ""; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--ink);
  border-radius: 50%; animation: wmspin .8s linear infinite; }
@keyframes wmspin { to { transform: rotate(360deg); } }
@media print { .sheet { display: none !important; } }
