/* ============================================================
   BNN Quality Incoming — Design System
   Mobile-first · macOS-like motion · 4 themes
   ============================================================ */

:root {
  /* Brand */
  --brand: #E60013;
  --brand-2: #FF8A3D;
  --brand-grad: linear-gradient(135deg, #E60013 0%, #FF8A3D 100%);

  /* Motion (macOS-like) */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --dur: 320ms;
  --dur-fast: 300ms;
  --dur-slow: 360ms;

  /* Radii */
  --r-card: 20px;
  --r-input: 12px;
  --r-pill: 999px;

  /* Focus ring (macOS blue) */
  --focus: #0A84FF;
  --focus-bg: rgba(10, 132, 255, 0.10);

  /* Status */
  --ok: #30A14E;
  --warn: #C77700;
  --bad: #D70015;
  --ok-bg: rgba(48, 161, 78, 0.12);
  --warn-bg: rgba(199, 119, 0, 0.12);
  --bad-bg: rgba(215, 0, 21, 0.10);

  font-size: 16px;
}

/* ---------- Theme: Light (default) ---------- */
:root, [data-theme="light"] {
  --bg: #f5f5f7;
  --bg-soft: #ececf0;
  --card: #ffffff;
  --card-2: #f7f7f9;
  --seg-track: #e6e6ec;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.10);
  --line-soft: rgba(0, 0, 0, 0.06);
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.10), 0 24px 60px rgba(0,0,0,.18);
  --glass: rgba(255, 255, 255, 0.72);
  --overlay: rgba(0, 0, 0, 0.35);
  --brand-on: #E60013;
  color-scheme: light;
}

/* ---------- Theme: Dark ---------- */
[data-theme="dark"] {
  --bg: #161617;
  --bg-soft: #101011;
  --card: #232326;
  --card-2: #2c2c30;
  --seg-track: #35353b;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: rgba(255, 255, 255, 0.14);
  --line-soft: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.5), 0 24px 60px rgba(0,0,0,.65);
  --glass: rgba(28, 28, 30, 0.72);
  --overlay: rgba(0, 0, 0, 0.55);
  --brand-on: #ff4d5c;
  /* สถานะ: โทนสว่างขึ้นบนพื้นมืด ให้คอนทราสต์ผ่าน WCAG AA (ป้าย ผ่าน/ไม่ผ่าน/reject อ่านออกทุกที่) */
  --ok: #32D74B;
  --warn: #FFB340;
  --bad: #FF6961;
  --ok-bg: rgba(50, 215, 75, 0.16);
  --warn-bg: rgba(255, 179, 64, 0.16);
  --bad-bg: rgba(255, 105, 97, 0.16);
  color-scheme: dark;
}

/* ---------- Theme: Navy ---------- */
[data-theme="navy"] {
  --bg: #0b1524;
  --bg-soft: #081020;
  --card: #12233c;
  --card-2: #182c4a;
  --seg-track: #1e3a5f;
  --text: #eaf1fd;
  --muted: #93a6c4;
  --line: rgba(160, 190, 235, 0.22);
  --line-soft: rgba(160, 190, 235, 0.10);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.45);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45), 0 24px 60px rgba(0,0,0,.6);
  --glass: rgba(13, 27, 48, 0.74);
  --overlay: rgba(2, 8, 20, 0.6);
  --brand-on: #ff5a68;
  /* สถานะ: โทนสว่างบนพื้น navy ให้คอนทราสต์ผ่าน WCAG AA */
  --ok: #32D74B;
  --warn: #FFB340;
  --bad: #FF6961;
  --ok-bg: rgba(50, 215, 75, 0.16);
  --warn-bg: rgba(255, 179, 64, 0.16);
  --bad-bg: rgba(255, 105, 97, 0.16);
  color-scheme: dark;
}

/* ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* overflow-x บน html เท่านั้นที่ส่งผลถึง viewport จริง (ของ body ไม่ถูก propagate)
   ถ้าไม่ใส่ กล่อง position:fixed ที่ล้นขอบจะทำให้ปัดหน้าเว็บไปทางขวาได้ */
html { height: 100%; overflow-x: hidden; }
/* html ต้องมีสีเดียวกับ body — ไม่งั้นสีขาวเริ่มต้นของ html โผล่ตรงพื้นที่ที่ body ไม่ครอบ */
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Noto Sans Thai",
    "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
  /* หมายเหตุ: ห้ามใส่ overflow-x: hidden ที่ body — จะทำให้ body กลายเป็น scroll container
     แล้ว position: sticky ของ .topbar ใช้ไม่ได้ (หัวเว็บเลื่อนตามหน้า)
     ถ้าต้องกันเลื่อนแนวนอน ให้ใส่ที่ html เท่านั้น (ค่าของ root ถูกส่งต่อไป viewport) */
}
/* ปุ่ม/ช่องกรอกทุกตัวใช้ฟอนต์เดียวกับเนื้อหา — กันตัวอักษร (เช่น "เริ่มตรวจรับผัก" บนปุ่ม)
   หลุดไปใช้ฟอนต์ปุ่มเริ่มต้นของเบราว์เซอร์ (เช่น Leelawadee UI บน Windows) จนดูไม่เข้าชุดกับตัวอื่น */
button, input, select, textarea, optgroup { font-family: inherit; }
/* ============================================================
   ห้ามใช้ fill-mode `both` ตรงนี้ และห้ามใส่ transform ใน keyframe `to`
   `both` = forwards ด้วย จึงค้างค่าของ keyframe ปลายทางไว้ตลอดหลังเล่นจบ
   ผลคือ computed transform ของ body เป็น matrix(1,0,0,1,0,0) ไม่ใช่ none
   — เมทริกซ์เอกลักษณ์ก็ยังนับว่า "มี transform"

   พอ body มี transform มันจะกลายเป็นจุดยึดของ position:fixed ทุกตัวในหน้า
   แทนที่จะยึดกับกรอบหน้าจอ · .modal-veil ที่ inset:0 จึงสูงเท่า "เอกสาร"
   ไม่ใช่เท่าจอ แล้ว place-items:center ก็จัดกล่องไปไว้กลางเอกสาร = ตกนอกจอ
   ฉากมืดยังคลุมจอ (เพราะ veil สูงมาก) → เห็นแต่พื้นเบลอ ไม่เห็นกล่อง
   หน้ายิ่งยาวยิ่งหลุดไกล จึงโผล่เฉพาะหน้าที่มีข้อมูลเยอะและบนมือถือ
   .menu-pop .toast-holder .loading-veil .autosave โดนกลไกเดียวกันหมด

   `backwards` ให้เฉพาะค่าเริ่มต้นก่อนเล่น ไม่ค้างค่าปลายทาง
   ซึ่งพอแล้วเพราะปลายทางเท่ากับค่าปกติของ body อยู่แล้ว
   ============================================================ */
body.page-enter { animation: pageIn var(--dur-slow) var(--ease) backwards; }
@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
body.page-leave { animation: pageOut var(--dur-fast) var(--ease) both; }
@keyframes pageOut { to { opacity: 0; transform: translateY(-8px); } }

img, svg { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .35em; font-weight: 700; letter-spacing: -0.01em; }
p { margin: .25em 0; }
a { color: var(--focus); text-decoration: none; }

/* ---------- Focus ring + offset (ทุก interactive) ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--r-input);
}
.card:focus-visible, .cat-card:focus-visible { outline-offset: 4px; border-radius: var(--r-card); }

/* ---------- Layout ---------- */
.app-shell { max-width: 560px; margin: 0 auto; padding: 0 14px calc(28px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .app-shell { max-width: 720px; } .app-shell.wide { max-width: 1080px; } }

/* ===== โหมดไม่เลื่อนหน้าจอ (หัว + แถบ step ล็อก · ที่เหลือเลื่อนได้) ===== */
body.fixed-app { overflow: hidden; height: 100dvh; }
body.fixed-app .topbar { position: relative; flex: none; }
.app-fixed {
  height: calc(100dvh - var(--tb, 54px));
  display: flex; flex-direction: column; min-height: 0;
  max-width: 560px; margin: 0 auto; padding: 0 14px;
}
@media (min-width: 900px) { .app-fixed { max-width: 720px; } }
.app-fixed > .steps { flex: none; }
.app-fixed > .flex-fill { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
/* พื้นที่เลื่อนหลัก (ทุกอย่างใต้แถบ step) */
.app-fixed .scroll-main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
/* ซ่อนแถบเลื่อนให้หมด แต่ยังเลื่อนได้ทั้งนิ้วและล้อเมาส์ */
.app-fixed .scroll-main { scrollbar-width: none; -ms-overflow-style: none; }
.app-fixed .scroll-main::-webkit-scrollbar { width: 0; height: 0; }
/* พื้นที่เลื่อนภายใน — scrollbar บาง */
.scroll-in {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  padding-right: 2px;
}
.scroll-in::-webkit-scrollbar { width: 4px; }
.scroll-in::-webkit-scrollbar-track { background: transparent; }
.scroll-in::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.scroll-in::-webkit-scrollbar-thumb:hover { background: var(--muted); }
/* การ์ดในโหมดเลื่อนทั้งกรอบ — ไม่บังคับความสูง (กัน bug เลื่อนไม่ได้) */
.card.card-fixed { margin: 10px 0 12px; }
.card.card-fixed > .card-body { min-height: 0; }
.card.card-fixed > .card-foot { padding-top: 10px; }

/* ---------- Top bar (glass, macOS) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  /* 3 คอลัมน์: ซ้าย(โลโก้+บ้าน) | กลาง(แถบเมนู) | ขวา(โปรไฟล์)
     ใช้ grid เพื่อให้คอลัมน์กลางอยู่กลางหน้าจริง ไม่เลื่อนตามความกว้างของสองข้าง */
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-soft);
  transition: background-color var(--dur) var(--ease);
}
.topbar .spacer { display: none; }        /* ไม่ต้องใช้แล้วเมื่อเปลี่ยนเป็น grid 3 คอลัมน์ */
.topbar .tb-left { grid-column: 1; display: flex; align-items: center; gap: 8px; }
.topbar .tabbar, .topbar .mode-name { grid-column: 2; }
.topbar .tb-right { grid-column: 3; display: flex; align-items: center; justify-content: flex-end; }
/* ห้ามโลโก้กับปุ่มหด ไม่งั้นถูกบีบแบนตอนแถบเมนูกินที่ */
.topbar .logo-btn, .topbar .home-btn, .topbar .avatar-btn,
.topbar .user-btn { flex: none; }
.topbar .tb-right { gap: 6px; }

/* ปุ่มผู้ใช้ = วงกลม + ชื่อ + ลูกศร (จอแคบเหลือแค่วงกลม) */
.user-btn {
  display: flex; align-items: center; gap: 7px; padding: 3px 8px 3px 3px; cursor: pointer;
  border: 1px solid transparent; background: none; border-radius: 999px; color: var(--text); font: inherit;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.user-btn:hover { background: var(--card-2); border-color: var(--line-soft); }
.user-btn .avatar-btn { pointer-events: none; }
.user-btn .ub-name { font-size: 14px; font-weight: 600; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn .ub-caret { display: grid; place-items: center; color: var(--muted); transform: rotate(90deg); }
.user-btn.open .ub-caret { transform: rotate(-90deg); }
@media (max-width: 820px) { .user-btn .ub-name, .user-btn .ub-caret { display: none; } .user-btn { padding: 3px; } }
/* โลโก้ตัวอักษรล้วนในหัวเว็บ — สลับชุดตามธีม */
.logo-btn .lg-dark { display: none; }
[data-theme="dark"] .logo-btn .lg-light, [data-theme="navy"] .logo-btn .lg-light { display: none; }
[data-theme="dark"] .logo-btn .lg-dark, [data-theme="navy"] .logo-btn .lg-dark { display: block; }
.logo-btn img { height: 24px; width: auto; flex: none; max-width: none; }

/* ปุ่มหน้าหลัก + แถบทางเดินสามหน้าในหัวเว็บ */
.home-btn {
  width: 32px; height: 32px; flex: none; cursor: pointer; padding: 0;
  border: 0; background: none; color: var(--muted);   /* ไม่มีกรอบ — เป็นไอคอนล้วน */
  display: grid; place-items: center; border-radius: 8px;
  transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.home-btn:hover { color: var(--text); }
.home-btn:active { transform: scale(0.92); }
.tabbar { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tabbar .tb {
  display: flex; align-items: center; gap: 6px;
  position: relative; overflow: hidden;      /* กันคลื่นน้ำล้นออกนอกปุ่ม */
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 11px; border-radius: 10px;
  white-space: nowrap; transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.tabbar .tb:hover { color: var(--text); background: var(--card-2); }
.tabbar .tb.on { color: var(--text); font-weight: 800; background: var(--card-2); }
.tabbar .tb-sep { color: var(--line); font-size: 13px; flex: none; user-select: none; }
/* คลื่นน้ำกระจายจากจุดที่นิ้วแตะ — บอกว่ากดติดแล้ว */
.tabbar .tb .rip {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: currentColor; opacity: .26; transform: scale(0);
  animation: tb-rip 520ms cubic-bezier(.22,.61,.36,1) forwards;
}
@keyframes tb-rip { to { transform: scale(1); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tabbar .tb .rip { animation-duration: 1ms; } }
/* จอแคบ: โลโก้/โปรไฟล์กว้างตามเนื้อหา · แถบเมนูกินที่เหลือแล้ว "เลื่อนซ้ายขวา" ได้เมื่อแท็บล้น
   (เดิม 1fr auto 1fr ทำให้แถบกลางกินความกว้างเท่าเนื้อหาจนล้นออกนอกจอ เลื่อนไม่ได้) */
@media (max-width: 620px) {
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px;
    grid-template-columns: auto minmax(0, 1fr) auto; }
  .logo-btn img { height: 20px; }
  .tabbar { gap: 0; justify-content: flex-start; }
  .tabbar .tb { font-size: 12.5px; padding: 6px 7px; flex: none; }
  .tabbar .tb-sep { font-size: 11px; }
}
.tabbar .tb .ic { display: grid; place-items: center; color: currentColor; opacity: .85; }
.tabbar .tb .ic svg { width: 15px; height: 15px; }
@media (max-width: 520px) { .tabbar .tb .ic { display: none; } }
@media (max-width: 400px) {
  .logo-btn img { height: 18px; }
  .tabbar .tb { font-size: 11.5px; padding: 5px 5px; }
}

/* โลโก้ซ้าย = ปุ่มกลับหน้าหลัก */
.logo-btn {
  border: 0; background: none; padding: 4px 2px; cursor: pointer; display: flex; align-items: center;
  border-radius: 10px; transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.logo-btn:active { transform: scale(0.94); }
.logo-btn:hover { opacity: .8; }
.logo-btn img { height: 24px; display: block; }

/* ปุ่มไอคอน (ธีม) */
.icon-btn {
  width: 34px; height: 34px; flex: none; cursor: pointer; padding: 0;
  border-radius: 50%; border: 1px solid var(--line-soft); background: var(--card-2); color: var(--text);
  display: grid; place-items: center;
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.icon-btn:active { transform: scale(0.9); }

/* รูปโปรไฟล์ = ปุ่มเปิดเมนู */
.avatar-btn {
  width: 36px; height: 36px; flex: none; cursor: pointer; padding: 0; overflow: hidden;
  border-radius: 50%; border: 1.5px solid var(--line-soft); background: var(--brand-grad);
  display: grid; place-items: center;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-btn span { color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.avatar-btn:active { transform: scale(0.92); }
.avatar-btn.open { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(10,132,255,.22); }

/* sub logo ขวา (เดิม — สำรอง) */
.menu-btn {
  width: 40px; height: 40px; flex: none; cursor: pointer; padding: 5px;
  border-radius: 50%; border: 1px solid var(--line-soft); background: var(--card-2);
  display: grid; place-items: center;
}
.menu-btn img { width: 26px; height: 26px; display: block; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 800; flex: none;
}

/* ---------- Hamburger ---------- */
.hamburger {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line-soft);
  background: var(--card-2); cursor: pointer; display: grid; place-items: center; flex: none;
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.hamburger:active { transform: scale(0.92); }
.hamburger span { display: block; width: 17px; height: 2px; border-radius: 2px; background: var(--text); margin: 2.1px 0; transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease); }
.hamburger.open span:nth-child(1) { transform: translateY(6.2px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6.2px) rotate(-45deg); }

.menu-pop {
  position: fixed; z-index: 70; top: 58px; right: 12px; min-width: 236px; max-width: calc(100vw - 24px);
  background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 6px; transform-origin: top right;
  opacity: 0; transform: scale(0.9) translateY(-6px); pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.menu-pop.open { opacity: 1; transform: none; pointer-events: auto; }
.menu-pop .m-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.menu-pop .m-head .n { font-weight: 700; font-size: 14px; }
.menu-pop .m-head .e { font-size: 12px; color: var(--muted); word-break: break-all; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 12px; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 14.5px; font-weight: 500; border-radius: 10px; cursor: pointer; text-align: left;
  transition: background-color 160ms var(--ease);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--card-2); }
.menu-item .ic { width: 20px; display: grid; place-items: center; color: var(--muted); flex: none; }
.menu-item.danger .ic { color: var(--bad); }
.menu-item.danger { color: var(--bad); }
.menu-sep { height: 1px; background: transparent; margin: 4px 8px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card);
  box-shadow: var(--shadow); padding: 15px 14px; margin: 12px 0;
  transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.card .card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card .card-h .badge-step {
  width: 30px; height: 30px; border-radius: 10px; background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none;
}
.card .card-h h2 { font-size: 16.5px; margin: 0; }
.card .card-h .hint { font-size: 12px; color: var(--muted); margin: 0; }

/* Category cards (home) */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat-card {
  position: relative; border: 1px solid var(--line-soft); border-radius: var(--r-card);
  background: var(--card); box-shadow: var(--shadow); padding: 12px 12px 11px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; text-align: left; color: var(--text);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur) var(--ease);
}
.cat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.cat-card:active { transform: scale(0.97); }
.cat-card .emoji { font-size: 24px; line-height: 1.1; }
.cat-card .t { font-weight: 700; font-size: 14px; line-height: 1.25; }
.cat-card .d { font-size: 11px; color: var(--muted); line-height: 1.3; }
/* ============================================================
   หน้าหลักแบบไม่เลื่อน
   ฐานการออกแบบ = โทรศัพท์ปัจจุบัน iPhone 17 (402×874) ·
   17 Pro Max (440×956) · Galaxy S26 (412×915)
   การ์ดมีเพดานความสูง แล้วกระจายช่องว่างที่เหลือ (ไม่ยืดจนเวิ้งว้าง)
   ============================================================ */
.home-fit {
  display: flex; flex-direction: column;
  min-height: 0; flex: 1 1 auto; gap: 0;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  overflow: hidden;
}
.home-fit .ver-tag { margin-top: auto; padding-top: 10px; }
/* จอเตี้ย — บีบระยะให้ยังพอดีไม่ตกขอบ */
@media (max-height: 720px) {
  .home-fit .hero-act { margin-top: 10px; }
  .home-fit .hero-act > span { min-height: 62px; padding: 11px 13px; }
  .home-fit .hero-act .ha-ic { width: 38px; height: 38px; }
  .home-fit .stat3, .home-fit .menu-list, .home-fit .last-round, .home-fit .soon-strip { margin-top: 8px; }
  .home-fit .menu-list .ml-row { padding: 10px 13px; }
  .home-fit .stat3 .s3 .v { font-size: 17px; }
}
.home-fit .cat-grid { min-height: 0; gap: 11px; }
.home-fit .grid-main {
  flex: 0 1 auto; display: grid;
  grid-template-rows: repeat(2, minmax(88px, 152px));
}
.home-fit .grid-quick { flex: none; }
.home-fit .cat-card { min-height: 0; justify-content: center; padding: 13px 14px; gap: 3px; overflow: hidden; }
.home-fit .cat-card .emoji { font-size: 27px; }
.home-fit .cat-card .t { font-size: 15px; }
.home-fit .cat-card .d { font-size: 11.5px; }
.home-fit .cat-card .soon { top: 8px; right: 8px; font-size: 10px; padding: 2px 7px; }
/* เมนูด่วน — แบบ B: ซ้อนแนวตั้ง สูงคงที่ */
.home-fit .grid-quick .cat-card { height: 88px; padding: 11px 13px; gap: 2px; }
.home-fit .grid-quick .cat-card .emoji { font-size: 21px; }
.home-fit .grid-quick .cat-card .t { font-size: 14px; }
.home-fit .grid-quick .cat-card .d { font-size: 11px; }
.home-fit .section-t { margin: 12px 4px 7px; font-size: 12px; letter-spacing: .04em; flex: none; }
.home-fit .kpis { gap: 11px; margin: 11px 0 0; flex: none; }
.home-fit .kpi { padding: 11px 13px; }
.home-fit .kpi .k { font-size: 11.5px; }
.home-fit .kpi .v { font-size: 20px; margin-top: 2px; }

/* จอกว้างระดับ Pro Max / S26 Ultra — ขยายอีกขั้น */
@media (min-width: 428px) and (min-height: 900px) {
  .home-fit .grid-main { grid-template-rows: repeat(2, minmax(96px, 168px)); }
  .home-fit .cat-card .emoji { font-size: 30px; }
  .home-fit .cat-card .t { font-size: 15.5px; }
  .home-fit .grid-quick .cat-card { height: 94px; }
}
/* เครื่องรุ่นเล็ก/เก่า — บีบลงให้ยังพอดี ไม่ตกขอบ */
@media (max-width: 380px), (max-height: 760px) {
  .home-fit .cat-grid { gap: 9px; }
  .home-fit .cat-card { padding: 10px 11px; }
  .home-fit .cat-card .emoji { font-size: 22px; }
  .home-fit .cat-card .t { font-size: 13.5px; }
  .home-fit .cat-card .d { font-size: 10.5px; }
  .home-fit .grid-quick .cat-card { height: 78px; }
  .home-fit .grid-quick .cat-card .emoji { font-size: 19px; }
  .home-fit .grid-quick .cat-card .t { font-size: 13px; }
  .home-fit .section-t { margin: 9px 4px 5px; font-size: 11px; }
  .home-fit .kpis { gap: 8px; margin: 9px 0 0; }
  .home-fit .kpi { padding: 8px 11px; }
  .home-fit .kpi .k { font-size: 10.5px; }
  .home-fit .kpi .v { font-size: 17px; }
}
@media (max-height: 660px) {
  .home-fit .grid-main { grid-template-rows: repeat(2, minmax(76px, 120px)); }
  .home-fit .grid-quick .cat-card { height: 70px; }
  .home-fit .cat-card .d { display: none; }
}
.cat-card.disabled { opacity: .55; cursor: not-allowed; filter: saturate(.4); }
.cat-card .soon {
  position: absolute; top: 10px; right: 10px; font-size: 10.5px; font-weight: 700;
  padding: 3px 8px; border-radius: var(--r-pill); background: var(--card-2); border: 1px dashed var(--line); color: var(--muted);
}

/* ---------- Inputs ---------- */
.field { margin: 10px 0; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field .req { color: var(--brand-on); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; min-height: 44px;
  border-radius: var(--r-input); border: 1.5px solid var(--line);
  background: var(--card-2); color: var(--text);
  font: inherit; font-size: 16px;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3.5px rgba(10, 132, 255, .22); }
.input::placeholder { color: var(--muted); opacity: .8; }
.input.err { border-color: var(--bad); box-shadow: 0 0 0 3.5px rgba(215, 0, 21, .15); }
.f-err { font-size: 12px; color: var(--bad); margin-top: 5px; display: none; }
.f-err.show { display: block; animation: shake 360ms var(--ease); }
@keyframes shake { 20%,60% { transform: translateX(-3px);} 40%,80% { transform: translateX(3px);} }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Segmented (เพศ / ตัวเลือก) */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--card-2); border: 1px solid var(--line-soft); border-radius: 12px; padding: 4px; }
.seg button {
  padding: 10px 8px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg button:active { transform: scale(.96); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 9px 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-size: 14.5px; font-weight: 700; cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: 0 6px 18px rgba(230, 0, 19, .3); }
.btn-primary:hover { box-shadow: 0 8px 24px rgba(230, 0, 19, .4); }
.btn-ghost { background: var(--card-2); color: var(--text); border-color: var(--line-soft); }
.btn-ghost:hover { background: var(--card); }
.btn-outline { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-link { background: none; border: 0; color: var(--focus); font-weight: 600; min-height: 0; padding: 6px 4px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { flex: 1; }
/* แถวปุ่มท้ายการ์ด: ยืนยันเด่นกว่า ปุ่มรองแคบลง */
.btn-row.actions .btn { flex: 0 0 auto; padding: 9px 13px; }
.btn-row.actions .btn-primary { flex: 1 1 auto; }

/* ---------- Collapse (การ์ดยุบ/ขยาย smooth) ---------- */
.collapse { overflow: hidden; transition: height var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease); }
.collapse.hidden-c { height: 0 !important; opacity: 0; }

/* ---------- Wizard: เลื่อนซ้าย/ขวาทีละ step (แบบ iOS/macOS) ---------- */
.wizard { position: relative; }
.wz-panel { display: none; }
.wz-panel.is-active { display: block; }
.wz-panel.is-leaving { position: absolute; top: 0; left: 0; right: 0; pointer-events: none; }
.wz-panel.in-right { animation: wzInRight var(--dur) var(--ease) both; }
.wz-panel.in-left { animation: wzInLeft var(--dur) var(--ease) both; }
.wz-panel.out-left { animation: wzOutLeft var(--dur) var(--ease) both; }
.wz-panel.out-right { animation: wzOutRight var(--dur) var(--ease) both; }
@keyframes wzInRight { from { opacity: 0; transform: translateX(34px); } to { opacity: 1; transform: none; } }
@keyframes wzInLeft  { from { opacity: 0; transform: translateX(-34px); } to { opacity: 1; transform: none; } }
@keyframes wzOutLeft { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(-34px); } }
@keyframes wzOutRight{ from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(34px); } }

/* สรุปย่อของ step ที่ทำผ่านแล้ว — จัดกึ่งกลาง กรอบพอดีข้อความ */
.wz-recap {
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  background: var(--card-2); border: 1px solid var(--line-soft); border-radius: 12px;
  padding: 8px 10px; font-size: 12.5px; margin-bottom: 10px; line-height: 1.4; text-align: center;
}
.wz-recap .r-txt { flex: 0 1 auto; min-width: 0; }
.wz-recap .r-l1 { display: block; font-weight: 700; }
.wz-recap .r-l2 { display: block; color: var(--muted); margin-top: 1px; white-space: nowrap; }
.wz-recap button { flex: none; min-height: 28px; padding: 4px 10px; font-size: 12px; }

/* ---------- Steps indicator ---------- */
.steps { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 12px 2px 2px; }
.steps .s { justify-content: center; }
.steps .s {
  flex: 1; display: flex; align-items: center; gap: 7px; padding: 8px 10px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line-soft); color: var(--muted);
  font-size: 12px; font-weight: 700; transition: all var(--dur) var(--ease);
}
.steps .s.clickable { cursor: pointer; }
.steps .s.clickable:active { transform: scale(.96); }
.steps .s .n { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--line-soft); font-size: 11px; flex: none; transition: all var(--dur) var(--ease); }
.steps .s.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); border-color: var(--line); }
.steps .s.on .n { background: var(--brand-grad); color: #fff; }
.steps .s.done .n { background: var(--ok); color: #fff; }
.steps .s .t { display: block; white-space: nowrap; }
@media (max-width: 400px) {
  .steps { gap: 4px; }
  .steps .s { padding: 7px 7px; font-size: 11px; gap: 5px; }
  .steps .s .n { width: 18px; height: 18px; font-size: 10px; }
}

/* ---------- Combobox (dropdown + search + Tab chip เส้นประ) ---------- */
.cbx { position: relative; }
.cbx.open { z-index: 80; }                 /* กัน dropdown ถูกช่องที่อยู่ถัดไปทับ */
/* ยกทั้งฟิลด์ที่ combobox เปิดอยู่ให้ลอยเหนือฟิลด์ถัดไป (เช่น "รูปประกอบ")
   แก้บั๊ก: ใส่รูปแล้วเลือกปัญหา รูปทับเมนู dropdown (หนี stacking context ของ .d-row) */
.field.cbx-open { position: relative; z-index: 80; }
.prod-sec.cbx-front { position: relative; z-index: 80; }
.pdate-row.cbx-front { position: relative; z-index: 80; }
.cbx .cbx-panel {
  position: absolute; z-index: 90; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 14px;
  box-shadow: var(--shadow-lg); max-height: 264px; overflow: auto; padding: 6px;
  opacity: 0; transform: scale(.97) translateY(-4px); transform-origin: top center; pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.cbx.open .cbx-panel { opacity: 1; transform: none; pointer-events: auto; }
.cbx-item {
  padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 14.5px;
  transition: background-color 140ms var(--ease);
}
.cbx-item:hover, .cbx-item.active { background: var(--card-2); }
.cbx-item mark { background: transparent; color: var(--brand-on); font-weight: 700; }
.cbx-item.add-new { color: var(--focus); font-weight: 700; border-top: 1px dashed var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
.cbx-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }
.tab-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 7px;
  padding: 5px 11px; font-size: 12.5px; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: 12px; background: transparent;
  animation: chipIn var(--dur-fast) var(--ease) both;
}
.tab-chip b { color: var(--text); font-weight: 700; }
.tab-chip .key { border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: 11px; background: var(--card-2); }
@keyframes chipIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- ช่องเลขทะเบียนรถ 1XX 1234 จังหวัด ---------- */
.plate { display: grid; grid-template-columns: 84px 12px 92px minmax(0, 1fr); gap: 7px; }
@media (max-width: 360px) { .plate { grid-template-columns: 68px 10px 76px minmax(0, 1fr); gap: 5px; } }
/* ตัวคั่นบอกรูปแบบป้าย: "–" = ป้ายเก่า · ช่องว่าง = ป้ายใหม่ */
.plate .pl-sep {
  align-self: center; text-align: center; font-weight: 800; font-size: 15px;
  color: var(--muted); line-height: 1; user-select: none;
  transition: color var(--dur-fast) var(--ease);
}
.plate .input { text-align: center; font-weight: 700; padding: 10px 4px; }
.plate .prov-btn {
  display: flex; align-items: center; gap: 5px; min-width: 0;
  padding: 10px 10px; min-height: 44px; border-radius: var(--r-input);
  border: 1.5px solid var(--line); background: var(--card-2); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-align: left;
  transition: border-color var(--dur-fast) var(--ease);
}
.plate .prov-btn:hover { border-color: var(--focus); }
.plate .prov-btn .pv { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate .prov-btn .pv.ph { color: var(--muted); font-weight: 500; }
.plate .prov-btn .cv { flex: none; font-size: 10px; color: var(--muted); }

/* ---------- ทะเบียนรถที่ซัพรายนี้ใช้บ่อย (ดึงจากประวัติจริง) ---------- */
/* แถวเดียว เลื่อนแนวนอน — ทะเบียนมีได้ถึง 6 คัน ถ้าปล่อยตัดบรรทัดจะกินที่ 2-3 แถว */
.pchips {
  display: flex; flex-wrap: nowrap; gap: 6px;
  max-height: 0; opacity: 0; margin: 0;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  transition: max-height 420ms var(--ease), opacity 320ms var(--ease), margin 320ms var(--ease);
}
.pchips::-webkit-scrollbar { display: none; }
.pchips.show { max-height: 52px; opacity: 1; margin: 8px 0 2px; }
.pchip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 7px 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--card-2); color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.pchip:active { transform: scale(.95); }
.pchip.on { border-color: var(--focus); background: var(--focus-bg); color: var(--focus); }
.pchip.new { border-style: dashed; }

/* ---------- ป้ายวันที่แบบยุบ + ดินสอ ---------- */
.dpill {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 12px; padding: 8px 10px;
  transition: opacity var(--dur-fast) var(--ease);
}
.dpill .dtxt { flex: 1; min-width: 0; font-size: 12.8px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dpill .dtxt .ar { color: var(--muted); margin: 0 3px; }
.dpill .dedit {
  flex: none; width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line-soft); background: var(--card-2); color: var(--muted);
  display: grid; place-items: center; transition: all 160ms var(--ease);
}
.dpill .dedit:hover, .dpill .dedit.on { border-color: var(--focus); color: var(--focus); }
.dedit-box { display: none; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.dedit-box.open { display: grid; animation: chipIn var(--dur-fast) var(--ease) both; }
.dedit-box .field { margin: 0; }
.dedit-box label { font-size: 11px; margin-bottom: 3px; }
/* date input ให้ตรงกับธีม */
input[type="date"].input, input[type="time"].input {
  -webkit-appearance: none; appearance: none;
  background: var(--card-2); color: var(--text); border-radius: var(--r-input);
  min-height: 42px; padding: 8px 10px; font-size: 14.5px;
}
input[type="date"].input::-webkit-calendar-picker-indicator {
  filter: none; opacity: .6; cursor: pointer;
}
[data-theme="dark"] input[type="date"].input::-webkit-calendar-picker-indicator,
[data-theme="navy"] input[type="date"].input::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .75; }

/* ---------- แถววันผลิต/หมดอายุ รายสินค้า ---------- */
.pdate-row {
  border: 1px solid var(--line-soft); border-radius: 14px; padding: 11px 12px;
  background: var(--card-2); margin-top: 10px;
  animation: chipIn var(--dur-fast) var(--ease) both;
}
.pdate-row .pd-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pdate-row .pd-name { flex: 1; font-weight: 800; font-size: 14.5px; display: flex; align-items: center; gap: 7px; }
.pdate-row .pd-name .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-grad); flex: none; }
.pdate-row .pd-del {
  width: 28px; height: 28px; flex: none; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--line-soft); color: var(--muted); font-size: 12px; line-height: 1;
  display: grid; place-items: center; transition: all 160ms var(--ease);
}
.pdate-row .pd-del:hover { background: var(--bad); color: #fff; }
.pdate-row .field { margin: 0; }
.pdate-row .field label { font-size: 11.5px; margin-bottom: 4px; }
.pdate-row .input { min-height: 40px; padding: 8px 10px; font-size: 14.5px; }
.pdate-row .row2 { gap: 8px; }

/* Chips (สินค้าที่เลือก) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 8px 8px 13px;
  background: var(--card-2); border: 1px solid var(--line-soft); border-radius: var(--r-pill);
  font-size: 13.5px; font-weight: 600; animation: chipIn var(--dur-fast) var(--ease) both;
}
.chip .x {
  width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--line-soft); color: var(--muted); font-size: 12px; line-height: 1;
  display: grid; place-items: center; transition: all 160ms var(--ease);
}
.chip .x:hover { background: var(--bad); color: #fff; }

/* ---------- ช่องน้ำหนักรวม (มีหน่วยติดในกรอบ) ---------- */
.wkg { position: relative; }
.wkg .input { padding-right: 46px; }
.wkg .wkg-u {
  position: absolute; right: 1px; top: 1px; bottom: 1px; width: 42px;
  display: grid; place-items: center; pointer-events: none;
  font-size: 13px; font-weight: 700; color: var(--muted);
  border-left: 1px solid var(--line-soft); border-radius: 0 11px 11px 0; background: var(--card);
}

/* ---------- Temp input: พิมพ์เอง + ปุ่มสลับ +/− (XX.XX °C) ---------- */
/* ---------- ช่องอุณหภูมิ: ตัวเลขพิมพ์เอง + แถบเลื่อนจาก 0 + ปุ่ม − / + ทีละ 0.1 ---------- */
/* ช่องอุณหภูมิ — ดีไซน์ใหม่ให้ดู modern: ปุ่มกลม ลอยเบา ๆ · ตัวเลขเด่น · แถบหนาโค้งมน */
.tsl { border: 1px solid var(--line-soft); border-radius: 18px; background: var(--card-2); padding: 16px 16px 14px; }
.tsl-row { display: flex; align-items: center; gap: 12px; }
.tsl-b {
  width: 50px; height: 50px; flex: none; border: 0; border-radius: 50%;
  background: var(--card); color: var(--brand-on); font: 500 26px/1 system-ui;
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.10);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.tsl-b:hover { background: var(--card-2); }
.tsl-b:active { transform: scale(.9); box-shadow: none; }
.tsl-num { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: center; gap: 5px; }
/* กว้างตามจำนวนตัวเลขจริง (JS ตั้ง width เป็น ch) เลขกับ °C จะได้อยู่กลางแถวพอดี */
.tsl input.tsl-in {
  width: 4ch; border: 0; background: transparent; text-align: center; outline: none; padding: 0;
  font-family: inherit; font-size: 46px; font-weight: 800; line-height: 1;
  color: var(--brand-on); font-variant-numeric: tabular-nums; letter-spacing: -1.5px;
}
@media (max-width: 360px) {
  .tsl input.tsl-in { font-size: 38px; }
  .tsl-b { width: 46px; height: 46px; }
}
.tsl input.tsl-in::placeholder { color: var(--line); }
.tsl.empty input.tsl-in { color: var(--muted); }
.tsl.neg input.tsl-in { color: var(--focus); }
.tsl-u { font-size: 15px; font-weight: 700; color: var(--muted); }

.tsl-sl { position: relative; height: 34px; margin: 16px 4px 0; display: flex; align-items: center; }
.tsl-tk { position: absolute; left: 0; right: 0; height: 8px; border-radius: 4px; background: var(--seg-track); }
.tsl-zero { position: absolute; top: 8px; width: 2px; height: 18px; border-radius: 1px; background: var(--line); }
.tsl-fill { position: absolute; height: 8px; border-radius: 4px; background: var(--brand-on); }
.tsl.empty .tsl-fill { background: var(--line); }
.tsl.neg .tsl-fill { background: var(--focus); }
.tsl-sl input[type=range] {
  position: relative; width: 100%; margin: 0; height: 34px; background: transparent;
  -webkit-appearance: none; appearance: none; outline: none;
}
.tsl-sl input[type=range]::-webkit-slider-runnable-track { height: 34px; background: transparent; }
.tsl-sl input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-on); border: 3px solid var(--card); margin-top: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.28); transition: transform var(--dur-fast) var(--ease);
}
.tsl.empty .tsl-sl input[type=range]::-webkit-slider-thumb { background: var(--muted); }
.tsl.neg .tsl-sl input[type=range]::-webkit-slider-thumb { background: var(--focus); }
.tsl-sl input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
.tsl-sl input[type=range]::-moz-range-track { height: 34px; background: transparent; }
.tsl-sl input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand-on);
  border: 3px solid var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.28);
}
.tsl-ends {
  display: flex; justify-content: space-between; margin: 5px 4px 0;
  font-size: 11px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums;
}

/* ---------- รูปประกอบต่อสินค้า (ตอนตรวจรับ + หน้ารายการ) ---------- */
.ph-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ph-btns .btn { flex: none; }
.ph-cnt { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.ph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.ph-th { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line-soft); aspect-ratio: 1; background: var(--card-2); }
.ph-th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0; }
.ph-x:active { transform: scale(.9); }
.ph-link { color: var(--brand-on); text-decoration: none; font-weight: 600; white-space: nowrap; }
.ph-link:active { opacity: .7; }
/* thumbnail รูปในหน้า records (แตะเปิดดูรูปใหญ่ในแอป) */
.ph-rec { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 6px; max-width: 360px; }
.ph-rec .ph-th { text-decoration: none; display: block; }
.ph-rec .ph-th img { cursor: zoom-in; }
.ph-rec .ph-nolink { aspect-ratio: auto; padding: 6px 8px; font-size: 12px; color: var(--brand-on); font-weight: 600; display: grid; place-items: center; }

/* lightbox ดูรูปเต็มในแอป */
.lb-ov { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.86); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.lb-img { max-width: 96vw; max-height: 82vh; object-fit: contain; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.lb-x { position: absolute; top: 14px; right: 16px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0; }
.lb-x:active { transform: scale(.92); }
.lb-full { color: #fff; text-decoration: none; font-weight: 600; font-size: 14px; background: rgba(255,255,255,.14); padding: 9px 16px; border-radius: 999px; }
.lb-full:active { opacity: .7; }

/* ==================== Documents (FM-QA-006 ใบตรวจรับคุณภาพผัก) ==================== */
#doc-root { display: block; }
/* ---- hub ---- */
.dhub-h { padding: 14px 4px 2px; }
.dh1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.dsub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.dfchips { display: flex; gap: 7px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.dfchips::-webkit-scrollbar { display: none; }
.dfchip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 20px; padding: 7px 14px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.dfchip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.dbanner { display: flex; align-items: center; gap: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 13px 15px; box-shadow: var(--shadow); margin: 8px 0; }
.dbanner .dbd { flex: 1; min-width: 0; }
.dbanner .dbt { font-size: 14px; font-weight: 800; }
.dbanner .dbs { font-size: 12px; color: var(--muted); margin-top: 1px; }
.dbanner .dbs .rem { color: var(--brand); font-weight: 700; }
.dbanner .dgo { flex: none; background: var(--brand); color: #fff; border: 0; border-radius: 11px; font: inherit; font-weight: 800; font-size: 13px; padding: 10px 14px; cursor: pointer; }
.dbanner .dgo:active { transform: scale(.97); }
.dgrp { margin-top: 18px; }
.dgrp-h { display: flex; align-items: center; gap: 10px; margin: 0 4px 9px; }
.dgrp-h .dic { width: 34px; height: 34px; flex: none; border-radius: 11px; background: color-mix(in srgb, var(--brand) 11%, var(--card)); display: grid; place-items: center; font-size: 16px; }
.dgrp-nm { min-width: 0; }
.dnm2 { font-weight: 800; font-size: 16px; letter-spacing: -.01em; display: block; }
.dmeta { font-size: 11px; color: var(--muted); font-weight: 500; display: block; margin-top: 1px; }
.dgrp-h .dcnt { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 700; background: var(--card-2); border-radius: 20px; padding: 4px 11px; white-space: nowrap; }
.dcard { display: flex; align-items: center; gap: 13px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 15px; margin: 8px 0; box-shadow: var(--shadow); cursor: pointer; font: inherit; color: var(--text); transition: transform .1s; }
.dcard:active { transform: scale(.99); }
.dcard .dst { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 17px; font-weight: 800; }
.dcard.pass .dst { background: var(--ok-bg); color: var(--ok); }
.dcard.fail .dst { background: var(--bad-bg); color: var(--bad); }
.dcard.todo .dst { background: var(--card-2); color: var(--muted); border: 2px dashed var(--line); }
.dcard .dmid { flex: 1; min-width: 0; }
.dcard .dnm { font-weight: 700; font-size: 15px; display: block; }
.dcard .dmt { font-size: 11.5px; color: var(--muted); font-weight: 500; display: block; margin-top: 1px; }
.dcard .dbg { font-size: 11px; font-weight: 800; border-radius: 7px; padding: 3px 9px; display: inline-block; margin-top: 5px; }
.dcard.pass .dbg { background: var(--ok-bg); color: var(--ok); }
.dcard.fail .dbg { background: var(--bad-bg); color: var(--bad); }
.dcard.todo .dbg { background: var(--card-2); color: var(--muted); }
.dcard .dcv { flex: none; color: var(--muted); font-size: 22px; }
/* ---- form (UX แบบ A · โทนเข้าถึงได้ WCAG) ---- */
#doc-root { --d-ok: #1E7E34; --d-bad: #C20012; --d-oktext: #1E7E34; --d-warntext: #8A5300; }
[data-theme="dark"] #doc-root, [data-theme="navy"] #doc-root { --d-oktext: #32D74B; --d-warntext: #FFB340; }
#doc-root button:focus-visible, #doc-root textarea:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 10px; }
.dctx { position: sticky; top: 52px; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); border-bottom: 1px solid var(--line); }
.dctx-in { padding: 9px 2px; }
.dctx-row { display: flex; align-items: center; gap: 10px; }
.dnav { flex: none; min-height: 44px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 20px; font: inherit; font-weight: 700; font-size: 13px; padding: 7px 13px; cursor: pointer; }
.dnav:active { transform: scale(.95); }
.dctx-mid { flex: 1; min-width: 0; text-align: center; }
.dmat { font-weight: 800; font-size: 16px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dpos { font-size: 11px; color: var(--muted); font-weight: 600; }
.drchip { flex: none; border: 0; font: inherit; font-size: 12px; font-weight: 800; border-radius: 20px; padding: 7px 12px; white-space: nowrap; cursor: pointer; }
.drchip.wait { background: var(--card-2); color: var(--muted); }
.drchip.ok { background: var(--ok-bg); color: var(--d-oktext); }
.drchip.bad { background: var(--d-bad); color: #fff; }
.ddots { display: flex; justify-content: center; gap: 5px; margin-top: 8px; }
.ddot { width: 8px; height: 8px; border: 0; padding: 0; border-radius: 50%; background: var(--line); cursor: pointer; }
.ddot.on { background: var(--brand); width: 20px; border-radius: 4px; }
.ddot.bad { background: var(--d-bad); }
.dprog { height: 4px; border-radius: 3px; background: var(--line-soft); margin-top: 9px; overflow: hidden; }
.dprog > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.dtempwarn { display: flex; align-items: center; gap: 7px; margin-top: 9px; padding: 9px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--d-warntext); font-size: 13px; font-weight: 700; border: 1px solid var(--warn); }
.dwrap2 { padding-bottom: 8px; }
.dhdr { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); margin: 12px 0; overflow: hidden; }
.dhdr-top { display: flex; align-items: center; gap: 8px; padding: 13px 14px; width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.dhdr-top .dt { font-weight: 700; font-size: 14px; flex: 1; color: var(--text); }
.dhdr-top .dcx { color: var(--muted); font-size: 15px; transition: transform .2s; }
.dhdr.open .dhdr-top .dcx { transform: rotate(180deg); }
.dhdr-body { display: none; padding: 0 14px 13px; }
.dhdr.open .dhdr-body { display: block; }
.dkv { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 7px 14px; font-size: 13px; border-top: 1px solid var(--line-soft); padding-top: 11px; }
.dkv b { color: var(--muted); font-weight: 600; white-space: nowrap; }
.dkv span { text-align: right; font-weight: 600; }
.dkv .warn { color: var(--d-warntext); font-weight: 700; }
.dqa { display: flex; gap: 9px; margin: 14px 0 2px; }
.dallpass { flex: 1; min-height: 54px; border: 2px solid var(--d-ok); border-radius: 14px; background: var(--ok-bg); color: var(--d-oktext); font: inherit; font-weight: 800; font-size: 16px; cursor: pointer; }
.dallpass.done { background: var(--d-ok); color: #fff; }
.dcopy { flex: none; min-height: 54px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); font: inherit; font-weight: 700; font-size: 13px; padding: 0 15px; cursor: pointer; white-space: nowrap; }
.dallpass:active, .dcopy:active { transform: scale(.98); }
.dundo { text-align: center; margin: 8px 0 0; }
.dundo button { border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; font-weight: 700; font-size: 12.5px; border-radius: 20px; padding: 8px 15px; min-height: 40px; cursor: pointer; }
.dhint { font-size: 12.5px; color: var(--muted); text-align: center; margin: 9px 0 2px; }
.dsec { margin-top: 18px; }
.dsec-h { display: flex; align-items: center; gap: 9px; margin: 0 4px 9px; }
.dsec-h .dn { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.dsec-h .dtt { font-weight: 700; font-size: 13.5px; flex: 1; line-height: 1.25; }
.dsec-h .dct { font-size: 12px; font-weight: 700; color: var(--d-oktext); white-space: nowrap; }
.dsec-h .dct.bad { color: var(--d-bad); }
.ditem { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); margin: 8px 0; overflow: hidden; transition: border-color .2s, background .2s; }
.ditem.ispass { background: var(--ok-bg); border-color: transparent; box-shadow: none; }
.ditem.isfail { border-color: var(--d-bad); border-width: 1.5px; background: var(--bad-bg); }
.ditem.flash { animation: ditemflash .9s ease; }
@keyframes ditemflash { 0%,100% { box-shadow: 0 0 0 0 rgba(215,0,21,0); } 30% { box-shadow: 0 0 0 4px rgba(215,0,21,.5); } }
.ditem-row { display: flex; align-items: center; gap: 12px; padding: 10px 11px; }
.ditem-tx { flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; color: var(--text); }
.ditem.ispass .ditem-tx { color: var(--muted); }
.dseg { flex: none; display: flex; gap: 8px; }
.segb { min-width: 58px; min-height: 46px; border: 1.5px solid var(--line); border-radius: 11px; background: var(--card); color: var(--muted); font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .15s, color .15s, border-color .15s; }
.segb:active { transform: scale(.95); }
.segb.p { border-color: var(--d-ok); color: var(--d-oktext); }
.segb.f { border-color: var(--d-bad); color: var(--d-bad); }
.segb.p.on { background: var(--d-ok); color: #fff; border-color: var(--d-ok); }
.segb.f.on { background: var(--d-bad); color: #fff; border-color: var(--d-bad); }
.dnote { display: none; padding: 0 11px 12px; }
.ditem.isfail .dnote { display: block; }
.dnote .dnl { font-size: 12px; color: var(--d-bad); font-weight: 700; margin: 2px 0 8px; }
.dchips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.dchip { font: inherit; font-size: 13px; font-weight: 600; padding: 0 14px; min-height: 44px; border-radius: 999px; border: 1.5px solid var(--d-bad); background: var(--card); color: var(--d-bad); display: inline-flex; align-items: center; cursor: pointer; }
.dchip.on { background: var(--d-bad); color: #fff; }
.dnote textarea { width: 100%; font: inherit; font-size: 14px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 11px; background: var(--card); color: var(--text); resize: vertical; min-height: 46px; }
.dnote textarea:focus { outline: none; border-color: var(--d-bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.dbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: color-mix(in srgb, var(--bg) 90%, transparent); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-top: 1px solid var(--line); padding: 9px 12px calc(9px + env(safe-area-inset-bottom)); }
.dbar-in { max-width: 560px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.dicon { width: 50px; height: 50px; flex: none; border-radius: 13px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 19px; cursor: pointer; display: grid; place-items: center; }
.dsave { flex: 1; min-height: 50px; border: 0; border-radius: 13px; background: var(--brand); color: #fff; font: inherit; font-weight: 800; font-size: 15px; cursor: pointer; transition: background .2s; }
.dsave.notready { background: var(--muted); }
.dicon:active, .dsave:active { transform: scale(.97); }
/* (ยกเลิก) เดิมเผื่อที่ให้แถบปุ่มล่างแบบ fixed — ตอนนี้แถบอยู่ในกล่อง pop-up แล้ว */
@media (prefers-reduced-motion: reduce) { #doc-root *, #doc-print * { transition: none !important; animation: none !important; } }
/* ---- print A4 (วางข้อความทับไฟล์ต้นฉบับ · ฟอนต์ Cordia New) ---- */
#doc-print { position: absolute; left: -99999px; top: 0; }
#doc-print .ovwrap { position: relative; width: 210mm; container-type: inline-size; font-family: 'BNNCordia', 'Cordia New', 'TH Sarabun New', 'Angsana New', sans-serif; }
#doc-print .ovwrap > svg { width: 100%; height: auto; display: block; }
#doc-print .pflogo { position: absolute; left: 42.65%; top: 1.7%; width: 7.9%; height: 5.6%; object-fit: contain; }
#doc-print .ov { position: absolute; transform: translateY(-50%); transform-origin: left center; white-space: nowrap; color: #111; font-size: 2.05cqw; font-weight: 400; display: inline-block; }
#doc-print .ov.ck { transform: translate(-50%, -50%); transform-origin: center center; font-weight: 700; font-size: 2.05cqw; color: #000; font-family: 'Segoe UI Symbol', 'Cordia New', sans-serif; }
#doc-print .ov.rm { transform: translateY(-50%); font-weight: 400; white-space: normal; max-width: 39%; line-height: 1.1; font-size: 2.05cqw; }
@media print {
  body.printing > * { display: none !important; }
  body.printing > #doc-print { display: block !important; position: absolute; left: 0 !important; top: 0; width: 100%; }
  @page { size: A4; margin: 0; }
}

/* ---------- ปุ่ม ✕ ล้างค่าในช่องค้นหา ---------- */
.cbx-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%) scale(.8);
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: var(--line-soft); color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.cbx-clear.show { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }
.cbx-clear:active { background: var(--line); transform: translateY(-50%) scale(.9); }
.cbx .cbx-clear.show + .input, .cbx > .input:has(~ .cbx-clear.show) { padding-right: 42px; }


/* ---------- Temp field: พิมพ์ได้ + spinner + เครื่องหมาย +/- ---------- */
.temp-field {
  display: flex; align-items: stretch; gap: 0;
  border: 1.5px solid var(--line); border-radius: var(--r-input);
  background: var(--card-2); overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.temp-field.focus { border-color: var(--focus); box-shadow: 0 0 0 3.5px rgba(10, 132, 255, .22); }
.temp-field.err { border-color: var(--bad); box-shadow: 0 0 0 3.5px rgba(215, 0, 21, .15); }
.temp-field .t-sign {
  width: 42px; flex: none; border: 0; border-right: 1px solid var(--line-soft);
  background: var(--card); color: var(--text); font: inherit; font-size: 19px; font-weight: 800;
  cursor: pointer; transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.temp-field .t-sign.neg { background: var(--bad); color: #fff; }
.temp-field input.t-num {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums; letter-spacing: .02em; padding: 10px 4px; min-height: 44px;
}
.temp-field input.t-num:focus { outline: none; }
.temp-field .t-unit {
  flex: none; display: grid; place-items: center; padding: 0 9px 0 3px;
  font-size: 15px; font-weight: 700; color: var(--muted);
}
.temp-field .t-spin { flex: none; display: flex; flex-direction: column; border-left: 1px solid var(--line-soft); }
.temp-field .t-spin button {
  width: 38px; flex: 1; border: 0; background: var(--card); color: var(--text);
  font-size: 10px; cursor: pointer; padding: 0; line-height: 1;
  transition: background-color 140ms var(--ease);
}
.temp-field .t-spin button:first-child { border-bottom: 1px solid var(--line-soft); }
.temp-field .t-spin button:active { background: var(--brand-grad); color: #fff; }

/* ---------- Temp picker (เดิม — สำรอง) ---------- */
.temp-wrap { position: relative; }
.temp-input { font-variant-numeric: tabular-nums; letter-spacing: .02em; cursor: pointer; }
.temp-pop {
  position: absolute; z-index: 56; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 12px;
  opacity: 0; transform: scale(.96) translateY(-4px); transform-origin: top center; pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.temp-pop.open { opacity: 1; transform: none; pointer-events: auto; }
.temp-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.temp-quick button {
  padding: 7px 11px; border-radius: var(--r-pill); border: 1px solid var(--line-soft);
  background: var(--card-2); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 160ms var(--ease);
}
.temp-quick button:hover { border-color: var(--focus); color: var(--focus); }
.temp-wheels { display: grid; grid-template-columns: 1.2fr auto 1fr 1fr auto; align-items: center; gap: 6px; }
.temp-wheels .sep { font-size: 24px; font-weight: 800; text-align: center; }
.wheel { height: 132px; overflow-y: auto; scroll-snap-type: y mandatory; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line-soft); scrollbar-width: none; }
.wheel::-webkit-scrollbar { display: none; }
.wheel .pad { height: 44px; }
.wheel .opt { height: 44px; display: grid; place-items: center; scroll-snap-align: center; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); cursor: pointer; transition: color 160ms var(--ease), transform 160ms var(--ease); }
.wheel .opt.sel { color: var(--text); transform: scale(1.12); }
.temp-pop .deg { font-size: 20px; font-weight: 800; color: var(--brand-on); text-align: center; }
.temp-actions { display: flex; gap: 8px; margin-top: 10px; }
.temp-actions .btn { flex: 1; }

/* ---------- Product section (การ์ด 3) ---------- */
.prod-sec {
  border: 1.5px solid var(--line-soft); border-radius: 16px; padding: 14px; margin: 12px 0;
  background: var(--card-2); animation: chipIn var(--dur) var(--ease) both;
}
.prod-sec .p-name { font-weight: 800; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.prod-sec .p-name .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand-grad); flex: none; }
.sample-box {
  margin-top: 9px; padding: 10px 11px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  display: flex; gap: 8px; align-items: flex-start;
  border: 1px solid var(--line-soft); background: var(--card);
  transition: all var(--dur) var(--ease);
}
.sample-box .big { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
/* ข้อความชวนกรอก: บรรทัดเดียว ไม่ตัดคำ */
.sample-box.hint { padding: 8px 11px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sample-box.hint > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sample-box.ok { background: var(--ok-bg); border-color: rgba(48,161,78,.4); color: var(--ok); }
.sample-box.warn { background: var(--warn-bg); border-color: rgba(199,119,0,.4); color: var(--warn); }
.sample-box.bad { background: var(--bad-bg); border-color: rgba(215,0,21,.4); color: var(--bad); }
.defect-rows .d-row { display: grid; grid-template-columns: 1fr 40px; gap: 8px; margin-top: 8px; animation: chipIn var(--dur-fast) var(--ease) both; align-items: center; }
.defect-rows .d-del { width: 40px; height: 44px; border-radius: 10px; border: 1px solid var(--line-soft); background: var(--card); color: var(--muted); cursor: pointer; transition: all 160ms var(--ease); }
.defect-rows .d-del:hover { color: var(--bad); border-color: var(--bad); }

/* ---------- Autosave badge ---------- */
.autosave {
  position: fixed; z-index: 58; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 7px;
  background: var(--glass); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line-soft); border-radius: var(--r-pill);
  padding: 7px 14px; font-size: 12px; font-weight: 600; color: var(--muted);
  box-shadow: var(--shadow); pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.autosave .dot-ok { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Modal ---------- */
/* ฉากหลังหยุดเลื่อนตอนมีหน้าต่างเปิด — คงตำแหน่ง scroll เดิมไว้ */
body.sheet-open {
  position: fixed; left: 0; right: 0; width: 100%;
  overflow: hidden; overscroll-behavior: none;
}
/* ============================================================
   เบลอพื้นหลังตอนเปิดหน้าต่าง — เบลอที่ "ตัวเนื้อหาเอง" ไม่ใช่ backdrop-filter

   ทำไมเลิกใช้ backdrop-filter:
   backdrop-filter ถ่าย snapshot ของสิ่งที่อยู่ข้างหลัง แล้วบางกรณีเบราว์เซอร์
   ไม่นับ element บางตัวเข้าไปใน snapshot นั้น (เจอจริง: แถวคำทักทายคมชัด
   อยู่แถวเดียวบนพื้นหลังที่เบลอทั้งจอ ไล่หาสาเหตุแล้วไม่คุ้มกับการเดาต่อ)
   วิธีนี้ใส่ filter ที่ element โดยตรง — ทุกพิกเซลของลูกทุกตัวถูกเบลอแน่นอน
   ไม่มี element ไหนหลุดได้ ไม่ว่าจะ composite ยังไง
   ยกเว้นเฉพาะตัวหน้าต่าง/toast ที่ต้องคมชัด
   ============================================================ */
body.sheet-open > *:not(.modal-veil):not(.loading-veil):not(.toast-holder):not(.fmqa-ov):not(script) {
  filter: blur(6px);
  transition: filter var(--dur) var(--ease);
}
.modal-veil {
  position: fixed; inset: 0; z-index: 90; background: var(--overlay);
  overscroll-behavior: contain;
  overflow: hidden;   /* กันชั้น blur ที่ล้นออกไป -48px ไปดันหน้าเว็บให้เลื่อนแนวนอนได้ */
  /* กล่องกลางจอทุกขนาด — เดิมมือถือเลื่อนขึ้นจากขอบล่าง ทำให้หน้าตาไม่ตรงกับหน้าอื่น */
  display: grid; place-items: center; padding: 18px;
  opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease);
}
/* ไม่ใช้ backdrop-filter แล้ว — ย้ายไปเบลอที่ตัวเนื้อหาเอง (ดู body.sheet-open ด้านบน)
   veil เหลือหน้าที่แค่ทำให้มืดลงและรับการแตะเพื่อปิด */
@media (min-width: 640px) { .modal-veil { padding: 24px; } }
.modal-veil.open { opacity: 1; pointer-events: auto; }
.modal {
  /* ทึบเสมอ รวมถึงตอนลากขีดเลื่อนลง */
  opacity: 1;
  position: relative; z-index: 1;   /* อยู่เหนือชั้น blur ::before เสมอ */
  width: 100%; max-width: 560px; max-height: 84dvh; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--line-soft);
  border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 16px 15px calc(14px + env(safe-area-inset-bottom));
  transform: translateY(14px) scale(.96); opacity: 0;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
}
@media (min-width: 640px) { .modal { max-height: 88dvh; } }
.modal-veil.open .modal { transform: none; opacity: 1; }
/* แถบจับปัดลงเพื่อปิด — พื้นที่กดกว้างกว่าที่เห็น กดง่ายด้วยนิ้ว */
.modal .grabber { display: none; }   /* กล่องกลางจอไม่ต้องมีแถบปัดลงปิด */
.modal .grabber-off {
  position: relative; width: 100%; height: 22px; margin: -8px 0 6px;
  background: none; cursor: grab; touch-action: none;
  display: grid; place-items: center;
}
.modal .grabber::after {
  content: ""; width: 40px; height: 4.5px; border-radius: 3px;
  background: var(--line); display: block;
  transition: background-color 160ms var(--ease), width 160ms var(--ease);
}
.modal .grabber:active { cursor: grabbing; }
.modal .grabber:active::after { background: var(--muted); width: 52px; }
/* เดิม .modal h3,.m-sub มี touch-action:none (เผื่อปัดปิดจากหัว) — ถอดออก เพราะ grabber ปิดแล้ว
   และมันบล็อกการเลื่อนเนื้อหา modal ที่ยาวเมื่อเริ่มนิ้วบนหัวเรื่อง · ปัดปิดจากตัว modal (scrollTop<=0) ยังทำงาน */
@media (min-width: 640px) { .modal .grabber { display: none; } }
.modal h3 { font-size: 16.5px; margin-bottom: 3px; }
.modal .m-sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
/* แถบปุ่มติดขอบล่างของกล่อง — ไม่ต้องเลื่อนหาปุ่มบนมือถือ */
.modal .btn-row {
  position: sticky; bottom: 0; z-index: 3;
  background: var(--card); padding: 14px 0 4px;
  margin-top: 10px; box-shadow: 0 -10px 16px -12px rgba(0,0,0,.3);
}
.modal .btn-row + .btn-row { margin-top: 0; padding-top: 0; box-shadow: none; }
/* ปุ่ม 2 แถวในกล่องเดียว — เดิมใช้ .btn-row 2 อันที่เป็น sticky ทั้งคู่ ทำให้เกยกันและเว้นช่องแปลก */
.modal .btn-stack {
  position: sticky; bottom: 0; z-index: 3;
  display: grid; gap: 8px;
  background: var(--card); padding: 12px 0 4px;
  margin-top: 12px; box-shadow: 0 -10px 16px -12px rgba(0,0,0,.3);
}
.modal .btn-stack .bs-row { display: flex; gap: 8px; }
.modal .btn-stack .bs-row .btn { flex: 1; }
.modal .rec { margin: 7px 0; padding: 11px 12px; }

/* ---------- Appearance picker (แบบ macOS) ---------- */
.appearance-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0 4px; }
@media (min-width: 560px) { .appearance-grid { grid-template-columns: repeat(4, 1fr); } }
.theme-tile { background: none; border: 0; padding: 0; cursor: pointer; text-align: center; font: inherit; color: var(--text); }
.theme-tile .prev {
  display: block; height: 72px; border-radius: 12px; border: 3px solid transparent; overflow: hidden; position: relative;
  box-shadow: var(--shadow); transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.theme-tile .lbl { font-size: 12.5px; margin-top: 5px; }
.theme-tile:hover .prev { transform: translateY(-2px); }
.theme-tile.sel .prev { border-color: var(--focus); }
.theme-tile .lbl { display: block; font-size: 12.5px; font-weight: 500; margin-top: 6px; color: var(--muted); }
.theme-tile.sel .lbl { font-weight: 800; color: var(--text); }
/* หน้าต่างจำลอง: แถบฟ้าอยู่เหนือหน้าต่าง · จุดสามสีอยู่มุมซ้ายบนในหน้าต่าง (ไม่ทับกัน) */
.prev .bar { position: absolute; top: 8px; left: 8px; right: 34%; height: 9px; border-radius: 5px; background: #0A84FF; display: block; }
.prev .win { position: absolute; left: 8px; right: 8px; top: 25px; bottom: -8px; border-radius: 8px 8px 0 0; display: block; }
.prev .dots { position: absolute; top: 5px; left: 6px; display: flex; gap: 3.5px; }
.prev .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.prev-light { background: linear-gradient(135deg,#dfe7f2,#f6e7d8); }
.prev-light .win { background: #ffffff; border: 1px solid rgba(0,0,0,.08); }
.prev-dark { background: linear-gradient(135deg,#20242e,#3a2f3a); }
.prev-dark .win { background: #26262a; border: 1px solid rgba(255,255,255,.1); }
.prev-navy { background: linear-gradient(135deg,#0a1a33,#20406e); }
.prev-navy .win { background: #12233c; border: 1px solid rgba(160,190,235,.2); }
.prev-auto { background: linear-gradient(115deg,#cfe0f5 49.5%, #2a2350 50.5%); }
.prev-auto .win { background: linear-gradient(115deg,#ffffff 49.5%, #2c2c30 50.5%); border: 1px solid rgba(0,0,0,.12); }

/* ---------- Toast ---------- */
/* z-index สูงกว่า .loading-veil (130) — toast แจ้งเตือน (เช่น error ระหว่างโหลด/อัปโหลด) ต้องเห็นเหนือฉากโหลดเสมอ */
.toast-holder { position: fixed; z-index: 140; top: calc(12px + env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--glass); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  color: var(--text); border: 1px solid var(--line-soft); border-radius: var(--r-pill);
  padding: 11px 18px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px; max-width: 92vw;
  animation: toastIn var(--dur-slow) var(--ease) both;
}
.toast.out { animation: toastOut var(--dur) var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) scale(.97); } }
.toast .ic-ok { color: var(--ok); } .toast .ic-bad { color: var(--bad); } .toast .ic-warn { color: var(--warn); }

/* ---------- Loading overlay (ใช้ mark loop) ---------- */
.loading-veil {
  position: fixed; inset: 0; z-index: 130; background: var(--overlay);
  overflow: hidden;   /* กันชั้น blur -48px ทำให้หน้าเว็บกว้างเกินจอ */
  display: grid; place-items: center; opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
/* loading-veil: เบลอด้วย backdrop-filter ต่อได้ เพราะโชว์แค่ชั่วครู่และไม่มีข้อความให้อ่าน */
.loading-veil::before {
  content: ""; position: absolute; inset: -48px; pointer-events: none;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.loading-veil.open { opacity: 1; pointer-events: auto; }
.loading-box { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; background: var(--card); border-radius: 20px; padding: 26px 34px; box-shadow: var(--shadow-lg); transform: scale(.94); transition: transform var(--dur) var(--ease); }
.loading-veil.open .loading-box { transform: none; }
.loading-box img { width: 64px; height: 64px; }
.loading-box .lt { font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- Table (รายการ/สรุป) ---------- */
.tbl-wrap { border-radius: 16px; overflow: auto; border: 1px solid var(--line-soft); background: var(--card); box-shadow: var(--shadow); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 640px; }
.tbl th { background: var(--card-2); font-weight: 700; text-align: center; padding: 10px 8px; border-bottom: 1.5px solid var(--line); position: sticky; top: 0; }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line-soft); text-align: center; }
.tbl td.l { text-align: left; }
.tbl tr:last-child td { border-bottom: 0; }
.num { font-variant-numeric: tabular-nums; }

/* KPI */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line-soft); border-radius: 16px; padding: 13px 14px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 3px; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 600; }
.bar-track { height: 7px; border-radius: 4px; background: var(--line-soft); overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--brand-grad); transition: width var(--dur-slow) var(--ease); }

/* Record item */
.rec {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 16px;
  box-shadow: var(--shadow); padding: 14px; margin: 10px 0; animation: chipIn var(--dur-fast) var(--ease) both;
}
.rec .r-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rec .r-sup { font-weight: 800; font-size: 15px; }
.rec .r-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.rec .r-items { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.rec .r-item { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: var(--r-pill); background: var(--card-2); border: 1px solid var(--line-soft); }
.rec .r-item.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.rec .r-item.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.rec .r-actions { display: flex; gap: 8px; margin-top: 12px; }
.status-pill { font-size: 11.5px; font-weight: 800; padding: 4px 10px; border-radius: var(--r-pill); flex: none; }
.status-pill.ok { background: var(--ok-bg); color: var(--ok); }
.status-pill.warn { background: var(--warn-bg); color: var(--warn); }
.status-pill.bad { background: var(--bad-bg); color: var(--bad); }
/* ชุดสถานะกลางของทั้งระบบ — Done · Pending · Reject · Info */
.status-pill.info { background: rgba(10,132,255,.12); color: var(--focus); }

/* ---------- LINE message box ---------- */
.line-box {
  background: var(--card-2); border: 1.5px dashed var(--line); border-radius: 14px;
  padding: 14px; font-size: 13.8px; white-space: pre-wrap; word-break: break-word;
  font-family: inherit; max-height: 46dvh; overflow: auto; line-height: 1.65;
  margin-bottom: 6px;
}

/* ---------- Auth page ---------- */
.auth-wrap { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
.auth-logo { width: min(300px, 74vw); margin-bottom: 6px; }
.auth-logo-dark { display: none; }
[data-theme="dark"] .auth-logo-light, [data-theme="navy"] .auth-logo-light { display: none; }
[data-theme="dark"] .auth-logo-dark,  [data-theme="navy"] .auth-logo-dark  { display: block; }
.auth-sub { color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 26px; text-align: center; }
.auth-card { width: 100%; max-width: 400px; }
.auth-view { transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.auth-view.hide { display: none; }
.auth-view.anim-in { animation: viewIn var(--dur-slow) var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
.auth-view.anim-back { animation: viewBack var(--dur-slow) var(--ease) both; }
@keyframes viewBack { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
/* เส้นคั่น "หรือ..." */
.or-line {
  display: flex; align-items: center; gap: 10px; margin: 12px 0 4px;
  font-size: 11.5px; color: var(--muted); font-weight: 600;
}
.or-line::before, .or-line::after { content: ""; flex: 1; height: 1px; background: var(--line); }
/* ปุ่มธีมหน้าก่อนล็อกอิน */
.auth-theme {
  position: fixed; z-index: 30; top: calc(12px + env(safe-area-inset-top)); right: 14px;
}
.ver-tag { margin-top: 18px; font-size: 11px; color: var(--muted); text-align: center; letter-spacing: .03em; }
.demo-banner {
  margin: 14px auto 0; max-width: 400px; font-size: 12.5px; color: var(--warn);
  background: var(--warn-bg); border: 1px solid rgba(199,119,0,.3); border-radius: 12px; padding: 10px 13px; text-align: center;
}
.g-btn, .ms-btn { background: var(--card); border: 1.5px solid var(--line); color: var(--text); }
/* ปุ่ม Google กับ Microsoft ต่อกัน — เว้นระยะให้เท่ากับช่องกรอกด้านล่าง */
.g-btn + .ms-btn { margin-top: 9px; }

/* ============================================================
   COLOR PICKER ขั้นสูง
   ============================================================ */
/* ตารางตัวอย่างจริง — แตะช่องไหน = เปลี่ยนสีส่วนนั้น เห็นผลทันที */
.cp-mini { border: 1px solid var(--line-soft); border-radius: 12px; overflow: hidden; margin: 2px 0 10px; }
.cp-mini table { width: 100%; border-collapse: collapse; font-size: 9.5px; table-layout: fixed; }
.cp-mini td, .cp-mini th {
  padding: 6px 4px; border: 1px solid; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cp-z { cursor: pointer; position: relative; }
.cp-z.sel { outline: 2.5px solid var(--focus); outline-offset: -2.5px; }
.cp-now {
  display: flex; align-items: center; gap: 5px; padding: 7px 9px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  background: var(--card-2); border-top: 1px solid var(--line-soft);
}
.cp-now b { color: var(--focus); }
.cp-now svg { flex: none; }
/* ชิป 7 ส่วน — แถวเดียวเลื่อนแนวนอน ไม่กินความสูง */
.cp-tgs { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 3px; margin-bottom: 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.cp-tgs::-webkit-scrollbar { display: none; }
.cp-tgs .cp-tg { flex: none; white-space: nowrap; }

.cp-targets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 11px; }
.cp-tg {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; min-height: 30px; border-radius: var(--r-pill);
  border: 1px solid var(--line-soft); background: var(--card-2); color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
  transition: all 150ms var(--ease);
}
.cp-tg.on { border-color: var(--focus); color: var(--text); background: var(--card); box-shadow: var(--shadow); }
.cp-tg i { width: 12px; height: 12px; border-radius: 3px; display: block; flex: none; border: 1px solid rgba(0,0,0,.25); }

.cp-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.cp-cell {
  aspect-ratio: 1; padding: 0; border: 0; border-radius: 3px; cursor: pointer;
  transition: transform 130ms var(--ease), border-radius 130ms var(--ease);
}
.cp-cell:hover { transform: scale(1.16); border-radius: 5px; }
.cp-cell.on {
  border-radius: 5px; transform: scale(1.06);
  box-shadow: inset 0 0 0 2.5px #fff, 0 0 0 1.5px rgba(0,0,0,.5);
}

.cp-row { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 11px; align-items: end; margin-top: 12px; }
.cp-prev { display: flex; height: 42px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.cp-prev span { flex: 1; display: block; }
.cp-hex {
  text-transform: uppercase; letter-spacing: .08em; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 42px;
}

.cp-adv { display: none; margin-top: 11px; border-top: 1px solid var(--line-soft); padding-top: 11px; }
.cp-adv.open { display: block; animation: chipIn var(--dur-fast) var(--ease) both; }
.cp-sv { position: relative; height: 112px; border-radius: 10px; overflow: hidden; cursor: crosshair; touch-action: none; }
.cp-sv i { position: absolute; inset: 0; display: block; }
.cp-sv .cp-w { background: linear-gradient(to right, #fff, rgba(255,255,255,0)); }
.cp-sv .cp-b { background: linear-gradient(to top, #000, rgba(0,0,0,0)); }
.cp-sv .cp-h {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 2.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 1px 4px rgba(0,0,0,.35);
  pointer-events: none; inset: auto;
}
.cp-hue {
  position: relative; height: 16px; border-radius: 8px; margin-top: 12px; touch-action: none; cursor: pointer;
  background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
}
.cp-hue .cp-h {
  position: absolute; top: -4px; width: 23px; height: 23px; margin-left: -11.5px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4); pointer-events: none; border: 0; inset: auto;
}

/* ---------- Color wall (เลือกเฉดสีตาราง — สำรอง) ---------- */
.cw-swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; margin-top: 6px; }
@media (max-width: 480px) { .cw-swatches { grid-template-columns: repeat(8, 1fr); } }
.cw-sw {
  aspect-ratio: 1; border-radius: 7px; border: 2px solid transparent; cursor: pointer; padding: 0;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}
.cw-sw:hover { transform: scale(1.14); }
.cw-sw.sel { border-color: var(--text); transform: scale(1.1); }
.cw-target { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.cw-target button {
  padding: 6px 11px; border-radius: var(--r-pill); border: 1px solid var(--line-soft);
  background: var(--card-2); color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  transition: all 150ms var(--ease);
}
.cw-target button.on { background: var(--card); color: var(--text); border-color: var(--focus); box-shadow: var(--shadow); }
.cw-preview { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--muted); margin-top: 9px; flex-wrap: wrap; }
.cw-preview i { width: 18px; height: 18px; border-radius: 6px; border: 1px solid var(--line-soft); display: block; }
/* color well + HEX */
.cw-hex { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 8px; align-items: center; margin: 10px 0 4px; }
.cw-well {
  display: block; width: 48px; height: 44px; border-radius: 12px; overflow: hidden;
  border: 1.5px solid var(--line); cursor: pointer; position: relative;
}
.cw-well input { position: absolute; inset: -25%; width: 150%; height: 150%; border: 0; padding: 0; cursor: pointer; background: none; }
.cw-code { font-family: var(--mono, ui-monospace, monospace); text-transform: uppercase; letter-spacing: .06em; text-align: center; min-height: 44px; }

/* ============================================================
   RECORDS layout ใหม่
   ============================================================ */
/* แถบค้นหา: ช่องค้นหา + ปฏิทิน + เมนู */
.rec-bar { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 7px; margin: 10px 0 4px; }
.rec-bar .input { min-height: 40px; font-size: 13.5px; }
.icon-sq {
  width: 40px; height: 40px; padding: 0; flex: none; cursor: pointer;
  display: grid; place-items: center; border-radius: 11px;
  border: 1px solid var(--line-soft); background: var(--card-2); color: var(--text);
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-sq:active { transform: scale(.92); }
.icon-sq.on { border-color: var(--focus); color: var(--focus); }
.icon-sq.danger { color: var(--bad); border-color: rgba(215,0,21,.35); }
.icon-sq.sm { width: 36px; height: 34px; border-radius: 10px; }

/* ตัวคั่นกลุ่มวัน */
.day-sep { display: flex; align-items: center; gap: 9px; margin: 16px 2px 8px; }
.day-sep .d1 { font-size: 11.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.day-sep .ln { flex: 1; height: 1px; background: var(--line-soft); }
.day-sep .d2 { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* การ์ดบันทึก */
.rec-card {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card);
  overflow: hidden; margin-bottom: 10px; box-shadow: var(--shadow);
  animation: chipIn var(--dur-fast) var(--ease) both;
}
.rec-card .rc-h { padding: 11px 13px 9px; }
.rec-card .rc-top { display: flex; align-items: flex-start; gap: 8px; }
.rec-card .rc-sup { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 800; line-height: 1.35; }
.rec-card .rc-meta { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.rec-card .rc-meta b { font-weight: 700; }
.rec-card .rc-meta b.bad { color: var(--bad); }
.rec-card .rc-meta b.ok { color: var(--ok); }

/* แถวสินค้า (แตะดูรายละเอียด) */
.rec-prow {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 10px 13px; border: 0; border-top: 1px solid var(--line-soft);
  background: transparent; color: var(--text); font: inherit; cursor: pointer; text-align: left;
  transition: background-color 160ms var(--ease);
}
.rec-prow:hover, .rec-prow:focus-visible { background: var(--card-2); }
.rec-prow .pdot { width: 7px; height: 7px; border-radius: 50%; flex: none; display: block; }
.rec-prow .pdot.ok { background: var(--ok); }
.rec-prow .pdot.bad { background: var(--bad); }
.rec-prow .pn { flex: 1; min-width: 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-prow .pq { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.rec-prow .pp { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-pill); flex: none; }
.rec-prow .pp.ok { background: var(--ok-bg); color: var(--ok); }
.rec-prow .pp.bad { background: var(--bad-bg); color: var(--bad); }
.rec-prow .pgo { flex: none; color: var(--muted); opacity: .65; display: grid; place-items: center; }

/* แถบปุ่มท้ายการ์ด */
.rec-acts {
  display: grid; grid-template-columns: minmax(0, 1fr) 36px 36px; gap: 7px;
  padding: 9px 11px; border-top: 1px solid var(--line-soft);
}
.rec-acts .btn { min-height: 34px; font-size: 12.5px; }

/* ตารางรายละเอียดในหน้าต่าง */
.detail-tbl { width: 100%; border-collapse: collapse; margin-top: 10px; }
.detail-tbl td { padding: 6px 0; font-size: 12.5px; vertical-align: top; }
.detail-tbl td:first-child { color: var(--muted); white-space: nowrap; width: 42%; font-size: 12px; }
.detail-tbl td:last-child { padding-left: 12px; }
.detail-tbl td.v-bad { color: var(--bad); font-weight: 700; }
.detail-tbl td.v-ok { color: var(--ok); font-weight: 700; }
.detail-tbl .sub { color: var(--muted); font-weight: 500; }

/* ============================================================
   HOME layout ใหม่ (action-first)
   ทุกการเปลี่ยนสถานะใช้ 300–360ms ด้วย --ease แบบ macOS
   ============================================================ */
/* ทักทายตามเวลา */
.greet-row { display: flex; align-items: center; gap: 11px; padding: 2px 2px 0; }
.greet-ic {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center; color: var(--gr-c, var(--muted));
  background: var(--gr-bg, var(--card-2));
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.greet-tx { flex: 1; min-width: 0; }
/* บรรทัด 1 ชื่อ · บรรทัด 2 วันที่+เวลา — ยาวเกินตัดด้วย … ไม่ดันขึ้นบรรทัดบน */
.greet-tx .g1 {
  display: block; font-size: 16px; font-weight: 800; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.greet-tx .g2 {
  display: block; font-size: 12px; color: var(--muted); line-height: 1.35; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* สีไอคอนทักทาย 7 ช่วงเวลา — ไล่จากม่วงเช้ามืด → ส้มเช้า → ทองเที่ยง → ส้มบ่าย → แดงเย็น → น้ำเงินค่ำ → ม่วงดึก */
.greet-ic.r-dawn  { --gr-bg: rgba(120,110,200,.16); --gr-c: #6f68c9; }
.greet-ic.r-morn  { --gr-bg: rgba(255,150,40,.15);  --gr-c: #e07a00; }
.greet-ic.r-noon  { --gr-bg: rgba(255,196,0,.20);   --gr-c: #c79000; }
.greet-ic.r-aft   { --gr-bg: rgba(255,138,61,.16);  --gr-c: #e2670e; }
.greet-ic.r-dusk  { --gr-bg: rgba(230,80,40,.14);   --gr-c: #d1502a; }
.greet-ic.r-eve   { --gr-bg: rgba(60,110,200,.15);  --gr-c: #3f6fc4; }
.greet-ic.r-night { --gr-bg: rgba(110,90,170,.18);  --gr-c: #7d63b8; }
/* ธีมมืด/navy — เพิ่มความสว่างของตัวไอคอนให้อ่านออก */
[data-theme="dark"] .greet-ic.r-dawn,  [data-theme="navy"] .greet-ic.r-dawn  { --gr-c: #9a93ea; }
[data-theme="dark"] .greet-ic.r-morn,  [data-theme="navy"] .greet-ic.r-morn  { --gr-c: #ffa94d; }
[data-theme="dark"] .greet-ic.r-noon,  [data-theme="navy"] .greet-ic.r-noon  { --gr-c: #ffd24d; }
[data-theme="dark"] .greet-ic.r-aft,   [data-theme="navy"] .greet-ic.r-aft   { --gr-c: #ff9c52; }
[data-theme="dark"] .greet-ic.r-dusk,  [data-theme="navy"] .greet-ic.r-dusk  { --gr-c: #ff7d5c; }
[data-theme="dark"] .greet-ic.r-eve,   [data-theme="navy"] .greet-ic.r-eve   { --gr-c: #79a6f0; }
[data-theme="dark"] .greet-ic.r-night, [data-theme="navy"] .greet-ic.r-night { --gr-c: #a98fe0; }

.greet-ic.r-accent { --gr-bg: rgba(10,132,255,.14); --gr-c: var(--focus); }
.greet-ic.r-warn { --gr-bg: var(--warn-bg); --gr-c: var(--warn); }
.greet-ic.r-bad { --gr-bg: var(--bad-bg); --gr-c: var(--bad); }
.greet-ic.r-pro { --gr-bg: rgba(123,94,167,.16); --gr-c: #9b7fc4; }

/* การ์ดปุ่มหลัก */
.hero-act {
  display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  text-align: left; margin-top: 13px;
}
.hero-act > span {
  display: flex; align-items: center; gap: 11px; min-height: 70px;
  padding: 14px 15px; border-radius: var(--r-card);
  background: var(--brand-grad); color: #fff;
  box-shadow: none;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.hero-act:active > span { transform: scale(.975); }
.hero-act .ha-ic {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: rgba(255,255,255,.22); color: #fff;
}
.hero-act .ha-t { flex: 1; min-width: 0; font-size: 16.5px; font-weight: 800; }
.hero-act .ha-go { flex: none; opacity: .9; }

/* สถิติ 3 ช่อง */
.stat3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 11px; }
.stat3 .s3 {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 11px;
  box-shadow: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat3 .s3 .k { display: block; font-size: 10.5px; color: var(--muted); font-weight: 600; transition: color var(--dur) var(--ease); }
.stat3 .s3 .v { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 1px; transition: color var(--dur) var(--ease); }
.stat3 .s3.alert { background: var(--warn-bg); border-color: rgba(199, 119, 0, .45); }
.stat3 .s3.alert .k, .stat3 .s3.alert .v { color: var(--warn); }

/* เมนูแบบรายการ */
.menu-list {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card);
  margin-top: 11px; overflow: hidden; box-shadow: none;
}
.menu-list .ml-row {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 12px 14px; border: 0; background: transparent; color: var(--text);
  font: inherit; cursor: pointer; text-align: left;
  transition: background-color 160ms var(--ease);
}
.menu-list .ml-row:hover, .menu-list .ml-row:focus-visible { background: var(--card-2); }
.menu-list .ml-row + .ml-row { border-top: 1px solid var(--line-soft); }
.menu-list .ml-ic { flex: none; color: var(--muted); display: grid; place-items: center; }
.menu-list .ml-tx { flex: 1; min-width: 0; }
.menu-list .ml-tx .t { display: block; font-size: 14px; font-weight: 700; }
.menu-list .ml-tx .d { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.menu-list .ml-go { flex: none; color: var(--muted); opacity: .7; }

/* การ์ดรอบล่าสุด */
.last-round {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card);
  padding: 11px 13px; margin-top: 11px; box-shadow: none;
  cursor: pointer; width: 100%; text-align: left; font: inherit; color: var(--text);
  animation: chipIn var(--dur) var(--ease) both;
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur) var(--ease);
}
.last-round:active { transform: scale(.985); }
.last-round .lr-h { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.last-round .lr-h .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.last-round .lr-h .tm { font-size: 10.5px; color: var(--muted); }
.last-round .lr-go { display: grid; place-items: center; color: var(--muted); opacity: .7; flex: none; }
.last-round .lr-b { display: flex; align-items: flex-start; gap: 8px; }
.last-round .lr-n { flex: 1; min-width: 0; }
.last-round .lr-n .n1 { display: block; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.last-round .lr-n .n2 { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

/* แถบหมวดที่ยังไม่เปิด */
.soon-strip {
  display: flex; align-items: center; gap: 8px; margin-top: 11px;
  padding: 9px 12px; border-radius: 12px; background: var(--card-2);
  font-size: 11px; color: var(--muted); line-height: 1.5;
}
.soon-strip svg { flex: none; opacity: .8; }

/* ============================================================
   DASHBOARD layout ใหม่
   ============================================================ */
/* แถบควบคุมยุบเป็นชิป */
.ctl-chips {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px;
  padding: 9px 0 11px; position: sticky; top: 0; z-index: 40;
  background: var(--bg);
}
.ctl-chip {
  display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 34px;
  padding: 6px 11px; border-radius: var(--r-pill);
  border: 1px solid var(--line-soft); background: var(--card); color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-align: left;
  transition: border-color 150ms var(--ease);
}
.ctl-chip:hover { border-color: var(--focus); }
.ctl-chip .cc-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctl-chip.on { border-color: var(--focus); color: var(--focus); }
.ctl-chip svg { flex: none; }

/* ตัวเลขหลัก */
.hero-kpi { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card); padding: 14px 15px; box-shadow: var(--shadow); }
.hero-kpi .hk-k { font-size: 12px; color: var(--muted); font-weight: 600; }
.hero-kpi .hk-row { display: flex; align-items: baseline; gap: 9px; margin-top: 3px; flex-wrap: wrap; }
.hero-kpi .hk-v { font-size: 32px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-kpi .hk-diff { font-size: 12px; font-weight: 700; }
.hero-kpi .hk-diff.up { color: var(--bad); }
.hero-kpi .hk-diff.down { color: var(--ok); }
.hero-kpi .hk-diff.flat { color: var(--muted); }
.hero-kpi .hk-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.hero-kpi .bar-track { height: 7px; margin-top: 10px; }

.mini-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 9px; }
/* การ์ดขาวมีขอบ+เงา — เดิมใช้พื้น --card-2 สีเดียวกับราง seg-tabs ที่อยู่ติดกัน
   ทำให้มองเหมือนกล่องไม่มีขอบล่างและกลืนเป็นก้อนเดียว */
.mini-kpi {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 12px;
  padding: 9px 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.mini-kpi.alert { border-color: rgba(215,0,47,.28); background: var(--bad-bg, rgba(215,0,47,.06)); }
.mini-kpi.alert .v { color: var(--bad); }
.mini-kpi .k { font-size: 10.5px; color: var(--muted); font-weight: 600; display: block; }
.mini-kpi .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; display: block; margin-top: 1px; }
.mini-kpi.warn { background: var(--warn-bg); }
.mini-kpi.warn .k, .mini-kpi.warn .v { color: var(--warn); }

/* แท็บสลับตาราง */
/* รางเข้มกว่าพื้นการ์ด เพื่อให้เห็นขอบเขตของแท็บชัด */
.seg-tabs { display: flex; gap: 3px; background: var(--seg-track, #e6e6ec); border: 1px solid var(--line-soft); padding: 3px; border-radius: 12px; margin: 14px 0 11px; }
.seg-tabs button {
  flex: 1; min-height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* การ์ด supplier แทนตาราง (ไม่ต้องปัดซ้ายขวา) */
.sup-card {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 14px;
  padding: 10px 12px; margin-bottom: 8px; animation: chipIn var(--dur-fast) var(--ease) both;
}
.sup-card .sc-top { display: flex; align-items: flex-start; gap: 8px; }
.sup-card .sc-n { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; line-height: 1.35; }
.sup-card .sc-p {
  flex: none; font-size: 11.5px; font-weight: 800; padding: 3px 9px; border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}
.sup-card .sc-p.ok { background: var(--ok-bg); color: var(--ok); }
.sup-card .sc-p.warn { background: var(--warn-bg); color: var(--warn); }
.sup-card .sc-p.bad { background: var(--bad-bg); color: var(--bad); }
.sup-card .sc-m { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.sup-card .sc-m b { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.sup-card .bar-track { height: 5px; margin-top: 8px; }
.sup-card .bar-fill.ok { background: var(--ok); }
.sup-card .bar-fill.warn { background: var(--warn); }
.sup-card .bar-fill.bad { background: var(--bad); }
.sort-row { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; }
.sort-row .sr-l { font-size: 11.5px; color: var(--muted); }

/* ป้ายบอกว่าเลื่อนได้ + ตารางตรึงคอลัมน์ซ้าย */
.scroll-hint {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--line-soft);
}
.tbl-wrap.sticky-first table.tbl th:first-child,
.tbl-wrap.sticky-first table.tbl td:first-child {
  position: sticky; left: 0; z-index: 3; background: var(--card); text-align: left; min-width: 128px;
}
.tbl-wrap.sticky-first table.tbl th:first-child { background: var(--card-2); z-index: 4; }
.tbl-wrap.tall { max-height: 52dvh; overflow: auto; }
/* ช่องเวลาเริ่มตรวจรับ — เน้นว่าระบบเติมให้อัตโนมัติ แต่แตะแก้ได้ */
.input.time-auto,
.plate .input.auto-fill {
  text-align: center; font-weight: 800; letter-spacing: .02em;
  border-color: var(--focus); background: var(--focus-bg); color: var(--focus);
}
.input.time-auto:focus,
.plate .input.auto-fill:focus { background: var(--card); color: var(--text); }

/* วันที่ พ.ศ. กำกับใต้ช่อง */
.date-be { font-size: 10.5px; color: var(--muted); text-align: center; margin-top: 3px; display: block; }

/* ---------- Filter picker (เลือก supplier / สินค้า ที่จะแสดง) ---------- */
.fl-summary {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line-soft);
  background: var(--card-2); color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-align: left;
  transition: border-color 160ms var(--ease);
}
.fl-summary:hover { border-color: var(--focus); }
.fl-summary .n { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 700; }
.fl-list { max-height: 46dvh; overflow: auto; border: 1px solid var(--line-soft); border-radius: 12px; margin-top: 8px; }
.fl-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line-soft); font-size: 14px;
}
.fl-item:last-child { border-bottom: 0; }
.fl-item:hover { background: var(--card-2); }
.fl-item input { width: 18px; height: 18px; flex: none; accent-color: var(--focus); }
.fl-item .t { flex: 1; }
.fl-item .c { font-size: 11.5px; color: var(--muted); font-weight: 700; }

/* ---------- Pagination (20 แถว/หน้า) ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0 2px; flex-wrap: wrap; }
.pager .pg-info { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.pager button {
  min-width: 34px; height: 32px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--line-soft); background: var(--card-2); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all 150ms var(--ease);
}
.pager button:hover:not([disabled]) { border-color: var(--focus); color: var(--focus); }
.pager button[disabled] { opacity: .4; cursor: not-allowed; }

/* Week/color controls */
.ctrl-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.color-dot { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); padding: 0; background: none; cursor: pointer; overflow: hidden; }
.color-dot input { width: 200%; height: 200%; transform: translate(-25%, -25%); border: 0; padding: 0; cursor: pointer; }
.preset-pill { padding: 7px 12px; border-radius: var(--r-pill); border: 1px solid var(--line-soft); background: var(--card-2); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; transition: all 160ms var(--ease); }
.preset-pill:hover { border-color: var(--focus); color: var(--focus); }

/* ============================================================
   DASHBOARD layout ใหม่ — การ์ดครอบตาราง + แถบไอคอน + แถบล่างติดจอ
   ============================================================ */
.tsec { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: hidden; }
.tsec-h { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.tsec-h b { font-size: 12.5px; font-weight: 800; flex: 1; min-width: 0; }
.tsec-hint { display: flex; align-items: center; gap: 4px; flex: none; font-size: 10px; font-weight: 600; color: var(--muted); }
.tsec-hint svg { flex: none; }
.tsec-f { display: flex; align-items: center; gap: 7px; padding: 0 10px 9px; }
/* แถบป้ายบอกวิธีใช้ — วางได้ 2 ป้ายไม่เบียดหัวตาราง */
.hint-bar { display: flex; align-items: center; gap: 9px; padding: 6px 11px; background: var(--card-2); border-bottom: 1px solid var(--line-soft); }
.tsec-hint.tap { color: var(--focus); }
/* แท็บเรียงลำดับ — อันที่ขาวคืออันที่ใช้อยู่ */
.sort-row .sr-l { flex: none; }
.seg-tabs.sort-seg { flex: 1; margin: 0; }
.seg-tabs.sort-seg button { min-height: 32px; font-size: 12.5px; }

/* ชิปบอกว่ากำลังกรองอะไรอยู่ — กด ✕ เพื่อกลับเป็นทั้งหมด */
.filt-chip {
  display: none; align-items: center; gap: 7px; margin: 0 0 9px;
  padding: 7px 8px 7px 11px; border-radius: 11px;
  background: var(--focus-bg, rgba(10,132,255,.10)); border: 1px solid var(--focus);
  color: var(--focus); font-size: 11.5px; font-weight: 700;
  animation: chipIn var(--dur-fast) var(--ease) both;
}
.filt-chip.show { display: flex; }
.filt-chip .ft { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.filt-chip .fx {
  width: 20px; height: 20px; flex: none; padding: 0; cursor: pointer;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--focus); color: #fff; font: inherit; font-size: 12px; line-height: 1;
}
.filt-chip .fx:active { transform: scale(.9); }

/* เมนูในหน้าต่างเมื่อแตะแถวตาราง (ทำตารางเดี่ยว) */
.mi-list { margin: 2px 0 4px; }
.mi-row {
  display: flex; align-items: center; gap: 11px; width: 100%; cursor: pointer;
  padding: 12px; margin-bottom: 7px; border-radius: 13px;
  border: 1px solid var(--line-soft); background: var(--card-2); color: var(--text);
  font: inherit; text-align: left;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.mi-row:active { transform: scale(.985); }
.mi-row .mi-ic {
  width: 32px; height: 32px; flex: none; border-radius: 10px;
  display: grid; place-items: center; background: var(--card); border: 1px solid var(--line-soft);
}
.mi-row .mi-tx { flex: 1; min-width: 0; }
.mi-row .mi-tx .t { display: block; font-size: 13.5px; font-weight: 700; }
.mi-row .mi-tx .d {
  display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mi-row.pri { border: 0; background: linear-gradient(100deg, var(--brand), var(--brand-2, #f4711f)); color: #fff; }
.mi-row.pri .mi-ic { background: rgba(255,255,255,.22); border: 0; color: #fff; }
.mi-row.pri .mi-tx .d { color: rgba(255,255,255,.86); }

/* ปุ่มช่วงเวลาที่กำลังใช้อยู่ */
.btn.pk { position: relative; }
.btn.pk.on { border-color: var(--focus); color: var(--focus); background: var(--focus-bg); }
.btn.pk .pk-tick { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 800; }

/* แถบเครื่องมือ 4 ช่องในบรรทัดเดียว (คัดลอกรูป / บันทึกรูป / ปรับสี / พอดีจอ) */
.tbar { display: flex; gap: 6px; padding: 0 10px 11px; }
.tbar button {
  flex: 1; min-width: 0; height: 50px; padding: 0 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 12px; border: 1px solid var(--line-soft); background: var(--card-2); color: var(--text);
  font: inherit; font-size: 10px; font-weight: 600; line-height: 1.1;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tbar button svg { width: 17px; height: 17px; flex: none; }
.tbar button:active { transform: scale(.94); }
.tbar button.on { border-color: var(--focus); color: var(--focus); }

/* ชิปกดติด/ดับ แทน checkbox */
.tog {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 11px; cursor: pointer;
  border-radius: 11px; border: 1px solid var(--line-soft); background: var(--card-2); color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 600;
  transition: border-color 160ms var(--ease), color 160ms var(--ease);
}
.tog i { position: relative; width: 15px; height: 15px; flex: none; display: block; border-radius: 4px; border: 1.5px solid var(--line); }
.tog.on { border-color: var(--focus); color: var(--focus); }
.tog.on i { background: var(--focus); border-color: var(--focus); }
.tog.on i::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: 2px solid #fff; border-top: 0; border-left: 0; transform: rotate(42deg);
}

/* หน้าที่มีแถบล่างติดจอ ไม่ต้องเผื่อ padding ล่างอีก */
.app-shell.has-foot { padding-bottom: 0; }
/* แถบล่างติดจอ — ไม่ต้องเลื่อนหา Export Excel */
.dash-foot {
  position: sticky; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 14px -14px 0; padding: 9px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-soft);
}
.dash-foot .btn { min-height: 44px; gap: 6px; }
.dash-foot .btn svg { flex: none; }

/* Weekly summary table (export)
   ทุกช่องเป็น 1 บรรทัดจบ — ชื่อซัพพลายเออร์ยาวแค่ไหนก็ไม่ตกบรรทัด
   หัวคอลัมน์แบ่งบรรทัดเองด้วย <br> ใน JS ไม่ปล่อยให้เบราว์เซอร์ตัด */
.wk-holder { padding: 8px; overflow: auto; }
.wk-table {
  border-collapse: separate; border-spacing: 0;
  width: auto; min-width: 100%; table-layout: auto;
  font-size: 13px; border-radius: 18px; overflow: hidden;
}
.wk-table th, .wk-table td { white-space: nowrap; }
/* มุมมองพอดีหน้าจอ — ย่อทั้งตารางตามสัดส่วนจริง (JS คำนวณ --wk-zoom) ไม่บีบคอลัมน์ */
.wk-holder.fit-window { overflow-x: hidden; }
.wk-holder.fit-window .wk-table { zoom: var(--wk-zoom, 1); }
.wk-table th, .wk-table td { padding: 9px 8px; text-align: center; border-right: 1.2px solid var(--wk-line, #7a4a3a); border-bottom: 1.2px solid var(--wk-line, #7a4a3a); color: var(--wk-text, #222); background: var(--wk-row, #fff); }
/* แถวข้อมูลแตะได้ → ทำตารางเดี่ยว */
.wk-table tbody tr.tapable { cursor: pointer; }
.wk-table tbody tr.tapable:active td { filter: brightness(.94); }
.wk-table th:last-child, .wk-table td:last-child { border-right: 0; }
.wk-table thead .wk-title th { background: var(--wk-head, #8f3f36); color: var(--wk-headtext, #fff); font-size: 15px; font-weight: 800; padding: 12px; border-bottom-width: 2px; }
.wk-table thead .wk-cols th { background: var(--wk-sub, #d9b8a6); font-weight: 700; }
.wk-table td.mat { background: var(--wk-band, #c98b7e); font-weight: 800; }
.wk-table td.supname { text-align: left; }
.wk-table tbody tr:last-child td { border-bottom: 0; }

/* ---------- Utilities ---------- */
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .center { text-align: center; }
.hide { display: none !important; }
.section-t { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty-state .big { font-size: 40px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   หน้าเลือกโหมดการทำงาน (mode.html)
   3 การ์ดใหญ่: ตรวจรับ · คืนสินค้า · ยืดอายุ
   ============================================================ */
.mode-page {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 56px 24px calc(56px + env(safe-area-inset-bottom));
  background: var(--bg);          /* สีเดียวทั้งหน้า ไม่ไล่เฉดให้ดูรกตา */
}
/* โลโก้ Quality Department — ชุดนิ่ง มีทั้งแบบสว่างและแบบมืด */
.mp-brand { margin-bottom: 40px; text-align: center; }
.mp-logo { width: min(320px, 78vw); display: block; }
.mp-logo-dark { display: none; }
[data-theme="dark"] .mp-logo-light, [data-theme="navy"] .mp-logo-light { display: none; }
[data-theme="dark"] .mp-logo-dark, [data-theme="navy"] .mp-logo-dark { display: block; }
.mp-h { font-size: 30px; font-weight: 800; letter-spacing: -.02em; text-align: center; margin: 0 0 8px; }
.mp-sub { font-size: 15px; color: var(--muted); text-align: center; margin: 0 0 36px; min-height: 22px; }
.mp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; width: 100%; max-width: 1060px; }
.mp-card {
  position: relative; background: var(--card); border: 1px solid var(--line-soft); border-radius: 22px;
  box-shadow: var(--shadow); padding: 36px 24px 30px; cursor: pointer; font: inherit; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 13px; text-align: center;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur) var(--ease);
}
.mp-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.mp-card:active { transform: scale(.985); }
/* ไอคอนลอยบนการ์ด — ไม่มีกล่องสี่เหลี่ยมพื้นหลัง */
.mp-ic { width: 56px; height: 56px; display: grid; place-items: center; flex: none; }
.mp-ic.green { color: var(--ok); }
.mp-ic.indigo { color: #6366F1; }
.mp-ic.amber { color: var(--warn); }
[data-theme="dark"] .mp-ic.indigo, [data-theme="navy"] .mp-ic.indigo { color: #9ea1ff; }
.mp-tx { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.mp-t { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.mp-d { font-size: 13.5px; color: var(--muted); line-height: 1.65; }
.mp-foot { margin-top: 34px; font-size: 12px; color: var(--muted); text-align: center; }
@media (min-width: 761px) { .mp-go { display: none; } }
/* มือถือ: การ์ดเรียงลงมาเป็นแถวแนวนอน ไม่ให้จอยาวเกินจนต้องเลื่อน */
@media (max-width: 760px) {
  .mode-page { padding: 30px 18px calc(30px + env(safe-area-inset-bottom)); justify-content: flex-start; }
  .mp-brand { margin-bottom: 22px; }
  .mp-logo { width: min(250px, 72vw); }
  .mp-h { font-size: 23px; }
  .mp-sub { font-size: 13.5px; margin-bottom: 22px; }
  .mp-grid { grid-template-columns: 1fr; gap: 13px; max-width: 460px; }
  .mp-card { flex-direction: row; align-items: center; text-align: left; gap: 13px; padding: 17px 16px; border-radius: 20px; }
  .mp-ic { width: 44px; height: 44px; }
  .mp-tx { flex: 1; min-width: 0; align-items: flex-start; gap: 3px; }
  .mp-t { font-size: 17px; }
  .mp-d { font-size: 12px; line-height: 1.5; }
  .mp-go { display: block; color: var(--muted); opacity: .55; flex: none; }
}

/* ปุ่มเลือกส่วนงานในหน้าลงทะเบียน — ข้อความยาวกว่าปุ่ม seg ทั่วไป
   min-width:0 จำเป็น: ปุ่มใน grid มี min-width:auto เป็นค่าเริ่มต้น จึงดันตัวเองล้นกรอบแทนที่จะตัดบรรทัด */
/* คอลัมน์ 1fr มี min เป็น min-content — ข้อความยาวจะดันคอลัมน์ให้กว้างเกินกรอบ
   ต้องเขียน minmax(0,1fr) ให้ยอมหดแล้วตัดบรรทัดแทน */
.seg-role { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.seg-role button {
  min-width: 0; font-size: 13px; padding: 9px 6px; line-height: 1.3;
  white-space: normal; overflow-wrap: break-word; text-align: center;
}
/* เงาแบบเดียวกับ .seg ทั่วไปฟุ้งกว้างเกิน ทำให้ปุ่มดูล้นกรอบ — ใช้เงาแคบลง */
.seg-role button.on { box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ==================== Records — layout split master–detail (.68) ==================== */
.rec-shell { max-width: 100%; padding-left: 0; padding-right: 0; }
.rec-shell > .rec-bar,
.rec-shell > .rec-dates,
.rec-shell > .rec-filter { padding-left: 14px; padding-right: 14px; }
.rec-shell > .rec-bar { margin-top: 2px; }

/* แถบวันที่ 14 วัน */
/* แถบวันที่: [ทั้งหมด][ปฏิทิน] ล็อกซ้ายไม่เลื่อน · วันทั้งเดือนเลื่อนแนวนอนได้ (ซ่อนแถบ scroll) */
.rec-dates { display: flex; align-items: stretch; gap: 8px; padding-top: 8px; padding-bottom: 4px; }
.rd-fixed { flex: none; display: flex; gap: 8px; align-items: stretch; }
.rd-scroll { flex: 1 1 auto; min-width: 0; display: flex; gap: 8px; align-items: stretch; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.rd-scroll::-webkit-scrollbar { display: none; height: 0; }
.rd-cal { flex: none; width: 46px; display: grid; place-items: center; border-radius: 13px; border: 1px solid var(--line-soft); background: var(--card); color: var(--text); cursor: pointer; transition: background-color var(--dur-fast) var(--ease), transform .12s var(--ease); }
.rd-cal:hover { background: var(--card-2); }
.rd-cal:active { transform: scale(.94); }
.rd-cal svg { width: 18px; height: 18px; }
.rdnav { flex: none; width: 30px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 10px; transition: background-color var(--dur-fast) var(--ease); }
.rdnav svg { width: 17px; height: 17px; }
.rdnav:hover { background: var(--card-2); color: var(--text); }
.rd-mo { flex: none; display: grid; place-items: center; padding: 0 8px; font-size: 12px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.rdchip { flex: none; min-width: 46px; padding: 6px 4px 5px; border: 1px solid var(--line-soft); background: var(--card); color: var(--text); border-radius: 13px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform .12s var(--ease); }
.rdchip:active { transform: scale(.94); }
.rdchip .dw { font-size: 10px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.rdchip .dn { font-size: 15px; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
.rdchip .dd { width: 4.5px; height: 4.5px; border-radius: 50%; background: var(--ok); opacity: 0; }
.rdchip.has .dd { opacity: 1; }
.rdchip.today .dn { color: var(--brand-on); }
.rdchip.sel { background: var(--text); border-color: var(--text); }
.rdchip.sel .dn, .rdchip.sel .dw { color: var(--bg); }
.rdchip.sel .dd { background: var(--bg); }
.rdchip.all { justify-content: center; min-width: 56px; }
.rdchip.all .dn { font-size: 12.5px; font-weight: 700; }

/* ตัวกรองสถานะเอกสาร */
.rec-filter { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 2px; }
.seg3 { display: inline-flex; background: var(--seg-track); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.seg3 button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: var(--r-pill); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease); }
.seg3 button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg3 .cnt { font-size: 11px; font-weight: 800; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; background: var(--warn-bg); color: var(--warn); }
.rec-cnt { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; padding-left: 12px; border-left: 1px solid var(--line-soft); }

/* split */
.rec-split { display: flex; min-height: 40vh; }
.rec-listpane { width: 100%; }
.rec-detailpane { display: none; }
@media (min-width: 900px) {
  /* ล็อกหน้า (แบบ macOS split view): หัวเว็บ + แถบค้นหา/วันที่/ตัวกรอง อยู่กับที่
     เลื่อนได้เฉพาะสองแผง · แผงซ้าย(รายการ) เลื่อนเอง "ซ่อนแถบ scroll" · แผงขวา(รายละเอียด) เลื่อนในตัวเอง ไม่ดันทั้งหน้า
     ใช้ :has() ทำ body เป็น flex column — ถ้าเบราว์เซอร์ไม่รองรับ จะ fallback เป็นหน้าเลื่อนปกติ (ไม่พัง) */
  body:has(> main.rec-shell) { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
  body:has(> main.rec-shell) > .topbar { position: static; flex: none; }
  .rec-shell { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
  /* แถบบน (ค้นหา/วันที่/ตัวกรอง) ไม่ถูกบีบ + จัดกึ่งกลางจำกัดความกว้าง ให้ align กับสองแผง
     (เลข วันที่จึงไม่โดนตัด · ทั้งหน้าไม่สยายเต็มจอกว้างจนดูโหรงเหรง) */
  /* เต็มความกว้างจอ (ไม่จัดกึ่งกลาง ไม่จำกัดความกว้าง) แบบ JobsDB — แถบบนไม่ถูกบีบ */
  .rec-shell > .rec-bar, .rec-shell > .rec-dates, .rec-shell > .rec-filter { flex: none; }
  .rec-split { flex: 1 1 auto; min-height: 0; align-items: stretch; gap: 0; }
  /* แผงซ้าย: สัดส่วน ~34% (กว้างสบาย ไม่บีบ) · ซ่อนแถบ scroll */
  .rec-listpane {
    flex: 0 0 clamp(380px, 34%, 660px); min-width: 0; border-right: 1px solid var(--line-soft);
    padding: 8px 20px 28px; align-self: stretch;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: none; -ms-overflow-style: none;   /* ห้ามมีแถบ scroll (ตามที่ผู้ใช้สั่ง) แต่ยังเลื่อนได้ */
  }
  .rec-listpane::-webkit-scrollbar { width: 0; height: 0; display: none; }
  /* แผงขวา: กินพื้นที่ที่เหลือทั้งหมด เนื้อหาเต็มแผง (ไม่จำกัดกว้าง) */
  .rec-detailpane {
    display: block; flex: 1 1 auto; min-width: 0; padding: 10px 32px 28px 32px;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  }
  .rec-detailpane::-webkit-scrollbar { width: 8px; }
  .rec-detailpane::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
  .rec-detailpane::-webkit-scrollbar-thumb:hover { background: var(--muted); }
  .rec-shell > .ver-tag { flex: none; padding: 4px 0 6px; }
}

/* day group + row */
.rgrp { padding: 0 2px; }
.rgrp-h { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 13px 6px 8px; font-size: 12px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.rgrp-n { margin-left: auto; font-weight: 600; }
.rrow { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; padding: 9px 10px; border-radius: 13px; position: relative; color: var(--text); font: inherit; transition: background-color var(--dur-fast) var(--ease); }
.rrow + .rrow { margin-top: 1px; }
.rrow:hover, .rrow:focus-visible { background: var(--card-2); outline: none; }
.rrow.sel { background: var(--card-2); }
.rrow.sel::before { content: ""; position: absolute; left: 2px; top: 9px; bottom: 9px; width: 3px; border-radius: 2px; background: var(--brand-on); }
.rrow-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: flex-start; margin-top: 6px; }
.rrow-dot.dot-ok { background: var(--ok); } .rrow-dot.dot-warn { background: var(--warn); } .rrow-dot.dot-bad { background: var(--bad); }
.rrow-main { flex: 1; min-width: 0; }
.rrow-sup { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rrow-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.rrow-doc { flex: none; font-size: 11.5px; font-weight: 700; }
.rrow-doc.ok { color: var(--ok); } .rrow-doc.warn { color: var(--warn); }

.list-empty { text-align: center; padding: 46px 16px; color: var(--muted); }
.list-empty .le-tx { font-size: 13.5px; margin-bottom: 14px; }

/* รายละเอียดรอบ (pane/sheet) */
.rd-head { padding: 4px 2px 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 12px; }
.rd-status { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.rd-doc { font-size: 12.5px; font-weight: 800; }
.rd-doc.ok { color: var(--ok); } .rd-doc.warn { color: var(--warn); }
.rd-sup { font-size: 19px; font-weight: 800; letter-spacing: -.01em; line-height: 1.3; }
.rd-meta { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 9px; }
.rd-meta .m { display: flex; flex-direction: column; }
.rd-meta .k { font-size: 11px; color: var(--muted); }
.rd-meta .v { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rd-meta .v.c-ok { color: var(--ok); } .rd-meta .v.c-bad { color: var(--bad); }
/* แถบปุ่ม: บรรทัดเดียว เลื่อนซ้ายขวาได้ (ไม่ตัดขึ้นบรรทัดใหม่) · ซ่อนแถบ scroll */
.rd-acts { display: flex; flex-wrap: nowrap; gap: 8px; margin-bottom: 14px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.rd-acts::-webkit-scrollbar { display: none; height: 0; }
.dact { flex: none; white-space: nowrap; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; padding: 9px 14px; border-radius: var(--r-pill); cursor: pointer; transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
/* ปุ่มปิด ✕ (มุมขวาบนของ pop-up มือถือ · sticky ตามเลื่อน) — เดสก์ท็อปซ่อน (แผงขวาไม่ต้องปิด) */
.rd-x { position: sticky; top: 0; float: right; z-index: 6; width: 34px; height: 34px; margin: -4px -4px -32px 0; border-radius: 50%; border: 1px solid var(--line-soft); background: var(--card); color: var(--text); display: grid; place-items: center; cursor: pointer; transition: background-color var(--dur-fast) var(--ease), transform .12s var(--ease); }
.rd-x:hover { background: var(--card-2); }
.rd-x:active { transform: scale(.92); }
.rd-x svg { width: 16px; height: 16px; }
.rec-detailpane .rd-x { display: none; }
.dact:hover { background: var(--card-2); } .dact:active { transform: scale(.96); }
.dact.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.dact.danger { color: var(--bad); border-color: var(--bad-bg); }
.dact.danger:hover { background: var(--bad-bg); }

.rd-mats { display: flex; flex-direction: column; gap: 12px; }
.rdmat { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-card); padding: 15px; box-shadow: var(--shadow); }
.mat-top { display: flex; align-items: center; gap: 8px; }
.mat-name { min-width: 0; font-size: 16px; font-weight: 800; line-height: 1.3; }
.mat-foot { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tbtn, .pbtn { border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 700; padding: 9px 15px; border-radius: var(--r-input); cursor: pointer; transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.tbtn:hover { background: var(--card-2); } .tbtn:active, .pbtn:active { transform: scale(.97); }
.pbtn { background: var(--text); color: var(--bg); border-color: transparent; }

.doc-pill { flex: none; font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: var(--r-pill); }
.doc-pill.done { background: var(--ok-bg); color: var(--ok); }
.doc-pill.wait { background: var(--warn-bg); color: var(--warn); }
.doc-pill.bad { background: var(--bad-bg); color: var(--bad); }
/* รหัสอ้างอิงต่อรายการ — chip นิ่ง ๆ (ใช้ได้ทุกธีม) · prefix จาง + tail เข้ม · เลือกทั้งก้อนคัดลอกง่าย */
.mat-top .doc-pill { margin-left: auto; }
.rc-chip { display: inline-flex; align-items: center; gap: 6px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; padding: 3px 9px; border-radius: 8px; background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line-soft); white-space: nowrap; -webkit-user-select: all; user-select: all; }
.rc-chip .rc-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); opacity: .5; flex: none; }
.rc-chip .rc-tail { color: var(--text); font-weight: 800; }

/* ตารางข้อมูล QA */
.kv { margin-top: 10px; }
.kv-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.kv-row:first-child { border-top: 0; }
.kv-k { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.kv-v { font-size: 13.5px; font-weight: 600; line-height: 1.5; min-width: 0; }
.kv-v .kv-sub { color: var(--muted); font-weight: 500; font-size: 12px; }
.kv-v.c-ok, .kv-v .c-ok { color: var(--ok); }
.kv-v.c-bad, .kv-v .c-bad { color: var(--bad); }
.kv-none { color: var(--muted); font-weight: 500; }

/* empty state แผงขวา */
.pane-empty { min-height: 60vh; display: flex; flex-direction: column; padding: 20px 26px 40px; }
.pe-head { display: flex; align-items: center; gap: 8px; font-size: 21px; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.pe-arrow { width: 21px; height: 21px; color: var(--muted); flex: none; }
.pe-hint { margin-top: 9px; font-size: 13.5px; color: var(--muted); max-width: 420px; line-height: 1.65; }
.pe-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; min-height: 240px; }
.pe-art { filter: drop-shadow(0 14px 34px rgba(0,0,0,.07)); }

/* ปฏิทินไทย (ในกล่อง ui.sheet) */
.cal { width: 100%; max-width: 300px; margin: 4px auto 0; }
.cal-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-my { font-size: 15px; font-weight: 800; }
.cal-nav { width: 34px; height: 34px; border: 0; background: none; color: var(--text); border-radius: 9px; cursor: pointer; display: grid; place-items: center; transition: background-color var(--dur-fast) var(--ease); }
.cal-nav:hover { background: var(--card-2); } .cal-nav:active { transform: scale(.9); }
.cal-nav svg { width: 18px; height: 18px; }
.cal-wd { display: grid; grid-template-columns: repeat(7,1fr); margin-bottom: 4px; }
.cal-wd span { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.cal-cell { position: relative; aspect-ratio: 1; border: 0; background: none; color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600; border-radius: 10px; cursor: pointer; display: grid; place-items: center; transition: background-color var(--dur-fast) var(--ease); }
.cal-cell.out { visibility: hidden; cursor: default; }
.cal-cell:hover:not(.out):not(.sel) { background: var(--card-2); }
.cal-cell.today { color: var(--brand-on); font-weight: 800; }
.cal-cell.today::after { content: ""; position: absolute; inset: 4px; border: 1.5px solid var(--brand-on); border-radius: 9px; opacity: .45; pointer-events: none; }
.cal-cell.sel { background: var(--text); color: var(--bg); }
.cal-cell.sel.today { color: var(--bg); }
.cal-cell.sel.today::after { border-color: var(--bg); opacity: .6; }
.cal-dot { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; border-radius: 50%; background: var(--ok); opacity: 0; }
.cal-cell.has .cal-dot { opacity: 1; }
.cal-cell.sel .cal-dot { background: var(--bg); }

/* ===== overlay ฟอร์มเอกสาร FM-QA (เปิดในหน้า Record · macOS scale+fade) ===== */
body.fmqa-open { overflow: hidden; }
/* กล่องเลื่อนเองในตัว — แถบหัว (.dctx) และแถบปุ่มล่าง (.dbar) ของฟอร์มจึงเกาะอยู่ "ในกรอบ pop-up"
   ไม่ใช่ยึดกับขอบจอแบบตอนยังเป็นหน้าเต็ม (เดิม .dbar เป็น position:fixed จึงกินเต็มความกว้างจอ) */
.fmqa-ov { position: fixed; inset: 0; z-index: 95; background: var(--overlay); display: grid; place-items: center; padding: 16px; overflow: hidden; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.fmqa-ov.on { opacity: 1; pointer-events: auto; }
.fmqa-panel {
  position: relative; width: 100%; max-width: 820px; max-height: 92dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--line-soft); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 0; transform: translateY(14px) scale(.97); opacity: 0;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
}
.fmqa-ov.on .fmqa-panel { transform: none; opacity: 1; }
/* ปุ่มปิดลอยอยู่มุมขวาบนของกล่อง (sticky จึงไม่เลื่อนหายตอนเลื่อนฟอร์ม) */
.fmqa-x { position: sticky; top: 10px; float: right; margin: 0 10px -38px 0; z-index: 30; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line-soft); background: var(--card); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.fmqa-x:active { transform: scale(.92); }
/* เนื้อฟอร์มมีระยะขอบของตัวเอง (เดิมได้จาก .app-shell ของหน้าเต็ม) */
.fmqa-ov #doc-root { padding: 0 14px 0; }
/* แถบหัว: เกาะบนสุดของกล่อง เต็มความกว้างกล่อง (bleed ออกจาก padding 14px)
   *** พื้นทึบ + ปิด backdrop-filter ในกล่อง ***
   backdrop-filter:blur() บน sticky element ที่อยู่ในกล่อง overflow:auto + border-radius
   = บั๊ก compositing ของ Chromium/Edge → เบลอทั้ง panel (เจอจริงบนเครื่องมี GPU · headless ไม่โผล่)
   ในกล่องการ์ดพื้นทึบอยู่แล้ว จึงไม่ต้อง frosted-glass — ใช้ var(--card) ทึบ ตัดบั๊กทิ้ง */
.fmqa-ov .dctx { position: sticky; top: 0; margin: 0 -14px; padding: 0 14px; border-radius: 20px 20px 0 0; background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; }
.fmqa-ov .dctx-row { padding-right: 46px; }   /* เว้นที่ให้ปุ่มปิด ไม่ทับชิปสถานะ */
/* แถบปุ่มล่าง: จาก fixed(ยึดจอ) → sticky ในกล่อง (พื้นทึบ ไม่ blur เหมือนกัน) */
.fmqa-ov .dbar { position: sticky; left: auto; right: auto; bottom: 0; margin: 8px -14px 0; padding: 9px 14px calc(9px + env(safe-area-inset-bottom)); border-radius: 0 0 20px 20px; background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; }
@media (max-width: 620px) { .fmqa-ov { padding: 8px; } .fmqa-panel { max-height: 96dvh; } }

/* ไอคอน SVG ในฟอร์มเอกสาร (แทนอีโมจิ) */
#doc-root .dsvg { width: 1.05em; height: 1.05em; vertical-align: -.18em; flex: none; }
#doc-root .dicon .dsvg { width: 20px; height: 20px; vertical-align: 0; }
#doc-root .dsave .dsvg { width: 18px; height: 18px; vertical-align: -.2em; }
#doc-root .dst .dsvg, #doc-root .dic .dsvg { width: 18px; height: 18px; }

/* เลือกหลายใบ: พิมพ์รวมไฟล์เดียว / ส่ง SharePoint แยกใบ */
.rd-multi { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 12px; background: var(--card-2); border: 1px solid var(--line-soft); border-radius: 14px; }
.mchk-all { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.mchk-all input, .mchk input { width: 18px; height: 18px; accent-color: var(--brand-on); cursor: pointer; }
.rd-multi .tbtn:disabled { opacity: .45; cursor: default; }
.mchk { display: inline-flex; align-items: center; flex: none; }
.mchk input:disabled { cursor: not-allowed; opacity: .4; }

/* fallback รูปเก่า (ไม่มี thumbnail ในบันทึก) — ไอคอน SVG ไม่ใช้อีโมจิ */
.ph-rec .ph-nolink { display: inline-flex; align-items: center; gap: 5px; }
.ph-rec .ph-nolink .phi { width: 15px; height: 15px; flex: none; opacity: .8; }

/* จัดการรูปจากหน้า Record (pop-up) */
.ps-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.ps-cell { position: relative; }
.ps-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ps-nofile { display: grid; place-items: center; height: 100%; font-size: 10.5px; line-height: 1.35; text-align: center; color: var(--muted); padding: 4px; }
.ps-new { position: absolute; left: 4px; bottom: 4px; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 999px; background: var(--ok); color: #fff; }
.ps-fetch { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; padding: 10px 12px; background: var(--warn-bg); border-radius: 12px; font-size: 12.5px; color: var(--warn); font-weight: 600; }

/* ========== รูปประกอบแบบ inline (ดู/ลบ/เพิ่ม ในแผงเลย · ไม่มี pop-up ซ้อน) ========== */
.ph-rec { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; max-width: 540px; }
.ph-rec .ph-th { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--card-2); border: 1px solid var(--line-soft); padding: 0; }
.ph-rec .ph-th > img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
/* พื้นทึบขึ้น ไม่ใช้ backdrop-filter — blur บนปุ่มที่อยู่ใน .ph-th (overflow+radius) เสี่ยงเบลอทั้ง thumbnail (บั๊ก compositing เดียวกับ .dctx/.dbar) */
.ph-rec .ph-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(18,18,20,.72); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; opacity: 0; transition: opacity .15s var(--ease); }
.ph-rec .ph-x > svg { width: 12px; height: 12px; }
.ph-rec .ph-th:hover .ph-x, .ph-rec .ph-fail .ph-x { opacity: 1; }
@media (hover: none) { .ph-rec .ph-x { opacity: 1; } }
.ph-rec .ph-add { display: grid; place-items: center; cursor: pointer; color: var(--muted); border-style: dashed; border-color: var(--line); background: transparent; transition: transform .12s var(--ease), color .15s; }
.ph-rec .ph-add > svg { width: 26px; height: 26px; }
.ph-rec .ph-add:hover { color: var(--brand-on); }
.ph-rec .ph-add:active { transform: scale(.94); }
.ph-rec .ph-load { display: grid; place-items: center; }
.ph-spin { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--brand-on); animation: ph-rot .7s linear infinite; }
@keyframes ph-rot { to { transform: rotate(360deg); } }
.ph-rec .ph-retry { position: absolute; inset: 0; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: color .15s; }
.ph-rec .ph-retry:hover { color: var(--brand-on); }
.ph-rec .ph-retry > svg { width: 26px; height: 26px; }
@media (prefers-reduced-motion: reduce) { .ph-spin { animation: none; } }
