/* ===== RST STORE — ธีมหลัก ===== */
:root {
  --bg: #0f1419;
  --bg-soft: #161d26;
  --card: #1b2430;
  --card-2: #212c3a;
  --line: #2b3949;
  --text: #e8eef5;
  --muted: #93a4b8;
  --brand: #ff8a1f;
  --brand-dark: #e5720c;
  --green: #2fbf71;
  --red: #ef4d4d;
  --yellow: #f5c542;
  --blue: #4a9eff;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* กฎ display ของคลาสต่างๆ (เช่น .thumb, button) ทับ attribute hidden ได้
   บังคับให้ hidden ชนะเสมอ ไม่งั้นช่องที่สั่งซ่อนไว้จะโผล่ออกมา */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }

/* ===== แถบบน ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.topbar .logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a {
  color: var(--muted);
  padding: 8px 13px;
  border-radius: 9px;
  white-space: nowrap;
  font-weight: 500;
}
.topbar nav a:hover { background: var(--card); color: var(--text); }
.topbar nav a.active { background: var(--brand); color: #22150a; font-weight: 700; }
.topbar .who { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ===== โครงหน้า ===== */
.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 18px 70px; }
h1 { font-size: 23px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 14px; margin-bottom: 18px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* ===== การ์ดสถิติ ===== */
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 15px 17px;
}
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 27px; font-weight: 700; line-height: 1.1; }
.stat .stat-unit { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.stat.green { border-left-color: var(--green); }
.stat.red { border-left-color: var(--red); }
.stat.blue { border-left-color: var(--blue); }

/* ===== ฟอร์ม ===== */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.field { margin-bottom: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 17px;
  background: var(--brand);
  color: #22150a;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--line); }
.btn-green { background: var(--green); color: #06230f; }
.btn-green:hover { background: #27a862; }
.btn-red { background: var(--red); color: #2a0808; }
.btn-red:hover { background: #d63c3c; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ===== ตาราง ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: var(--card-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge.green { background: rgba(47, 191, 113, 0.18); color: var(--green); }
.badge.red { background: rgba(239, 77, 77, 0.18); color: var(--red); }
.badge.yellow { background: rgba(245, 197, 66, 0.18); color: var(--yellow); }
.badge.blue { background: rgba(74, 158, 255, 0.18); color: var(--blue); }
.badge.gray { background: var(--card-2); color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 34px 12px; }

/* ===== แจ้งเตือน ===== */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(120%);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  box-shadow: var(--shadow);
  border-radius: 11px;
  padding: 13px 19px;
  max-width: min(520px, 92vw);
  z-index: 200;
  transition: transform 0.22s ease;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.ok { border-left-color: var(--green); }
#toast.err { border-left-color: var(--red); }

/* ===== กล่องซ้อน ===== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 150;
}
.modal-bg[hidden] { display: none; }
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ===== หน้าเข้าสู่ระบบ ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 20%, #1d2735, var(--bg) 60%);
}
.login-box { width: min(390px, 100%); }
.login-box .brand { text-align: center; margin-bottom: 24px; }
.login-box .brand .brand-logo { width: 160px; height: 160px; display: block; margin: 0 auto; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.45)); }
.login-box .brand h1 { font-size: 25px; margin: 8px 0 3px; }
.login-box .brand p { color: var(--muted); margin: 0; font-size: 14px; }
.pw-wrap { position: relative; }
.pw-wrap button {
  position: absolute;
  right: 6px;
  top: 6px;
  background: none;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 17px;
}
.pw-wrap button:hover { background: none; color: var(--text); }

/* ===== หน้าสแกน ===== */
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; }
#reader video { width: 100% !important; display: block; }
.scan-hint { color: var(--muted); font-size: 14px; text-align: center; margin: 12px 0 0; }
.mode-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.mode-tabs button {
  flex: 1;
  background: var(--card-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.mode-tabs button.active { background: var(--brand); color: #22150a; border-color: var(--brand); }
.mode-tabs button.active[data-type='OUT'] { background: var(--yellow); color: #2b2205; border-color: var(--yellow); }
.mode-tabs button.active[data-type='IN'] { background: var(--green); color: #06230f; border-color: var(--green); }

.part-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.part-head .code { color: var(--brand); font-weight: 700; font-size: 14px; letter-spacing: 0.5px; }
.part-head h2 { margin: 3px 0 0; }
.qty-big { font-size: 34px; font-weight: 700; line-height: 1; }
.qty-big small { font-size: 14px; color: var(--muted); font-weight: 400; }

.stepper { display: flex; gap: 10px; align-items: center; }
.stepper button { width: 52px; font-size: 22px; padding: 11px 0; }
.stepper input { text-align: center; font-size: 22px; font-weight: 700; }

/* ===== หน้าพิมพ์ QR ===== */
.qr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.qr-label {
  border: 1px dashed #999;
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  background: #fff;
  color: #000;
  break-inside: avoid;
}
.qr-label img { width: 100%; max-width: 130px; display: block; margin: 0 auto 4px; }
.qr-label .l-code { font-weight: 700; font-size: 13px; }
.qr-label .l-name { font-size: 11px; line-height: 1.25; height: 2.5em; overflow: hidden; }
.qr-label .l-loc { font-size: 10px; color: #555; }

/* ===== ฉลากสำหรับเครื่องพิมพ์ฉลาก (ขนาดเป็น มม. ตั้งจากหน้าพิมพ์) ===== */
.sticker-list { display: flex; flex-wrap: wrap; gap: 12px; }
.sticker {
  display: flex;
  align-items: center;
  background: #fff;
  color: #000;
  overflow: hidden;
  outline: 1px dashed #888; /* เส้นขอบไว้ดูตอนพรีวิวบนจอ ไม่ถูกพิมพ์ */
  font-family: 'Segoe UI', 'Noto Sans Thai', 'Sarabun', sans-serif;
}
.sticker.tall { flex-direction: column; justify-content: center; text-align: center; }
.sticker.tall .s-text { width: 100%; flex: 0 0 auto; } /* กว้างเต็มฉลาก ให้รหัสยาวๆ ตัดเป็น … แทนการล้นขอบ */
.sticker img { flex: 0 0 auto; display: block; image-rendering: pixelated; }
.sticker .s-text { min-width: 0; flex: 1; line-height: 1.15; }
.sticker .s-code { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticker .s-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.4mm;
}
.sticker .s-sub { color: #333; margin-top: 0.4mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== รูปสินค้า ===== */
.thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  display: block;
}
img.thumb { cursor: zoom-in; }
.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 19px;
}
.thumb-lg { width: 92px; height: 92px; font-size: 30px; }
.part-photo {
  width: 78px;
  height: 78px;
  object-fit: cover;
  border-radius: 11px;
  border: 1px solid var(--line);
}

/* ===== ตอนพิมพ์ =====
   ต้องใช้ !important ทั้งหมด: หน้าฉลากกว้างแค่ ~50 มม. เบราว์เซอร์จึงมองเป็น "จอมือถือ"
   กฎ @media (max-width: 768px) ที่อยู่ท้ายไฟล์จะทำงานตอนพิมพ์ด้วย และทับกฎตรงนี้ถ้าไม่บังคับ
   (เคยเกิดจริง: แถบเมนูล่างกับข้อความแจ้งเตือนถูกพิมพ์ทับ QR และมีหน้าเปล่าเกินมา) */
@media print {
  .topbar, .no-print, .bottomnav, #toast, .sheet-bg, .modal-bg { display: none !important; }
  html, body { background: #fff !important; color: #000 !important; }
  body, body.has-bottomnav { padding: 0 !important; margin: 0 !important; }
  .wrap { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .card { border: none !important; background: #fff !important; padding: 0 !important; margin: 0 !important; box-shadow: none !important; }
  .qr-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }

  /* โหมดเครื่องพิมพ์ฉลาก: 1 ดวงต่อ 1 หน้า ไม่มีกรอบ/ขอบใดๆ มาเบียดพื้นที่ */
  body.label-mode .sticker-list { display: block !important; }
  body.label-mode .sticker { outline: none !important; break-after: page; page-break-after: always; }
  body.label-mode .sticker:last-child { break-after: auto; page-break-after: auto; }
}

/* ===== ช่องรูปในฟอร์มสินค้า: ทั้งกรอบกดเพื่อถ่ายรูป ===== */
.photo-pick { display: flex; gap: 12px; align-items: flex-end; }
.photo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 150px;
  height: 150px;
  margin: 0;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--muted);
  font-size: 34px;
  text-align: center;
  line-height: 1.3;
  cursor: pointer;
  overflow: hidden;
}
.photo-box small { font-size: 13px; }
.photo-box:hover { border-color: var(--brand); }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }

/* ===== ส่วนข้อมูลเพิ่มเติมที่พับเก็บได้ ===== */
details.more {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  margin-bottom: 6px;
}
details.more > summary {
  cursor: pointer;
  padding: 14px 0;
  color: var(--muted);
  font-weight: 600;
  list-style-position: inside;
}
details.more[open] > summary { color: var(--text); margin-bottom: 4px; }

/* ===== จอเล็ก ===== */
.bottomnav, .sheet-bg, .m-only { display: none; }
td.c-title { font-weight: 700; }

@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ===================================================================
   มือถือ — แอปนี้ใช้บนโทรศัพท์เป็นหลัก
   =================================================================== */
@media (max-width: 768px) {
  body { font-size: 16px; }
  .wrap { padding: 16px 13px 24px; }
  h1 { font-size: 21px; }
  .card { padding: 15px; border-radius: 13px; }

  /* iOS ซูมเข้าเองทุกครั้งที่แตะช่องที่ตัวอักษรเล็กกว่า 16px */
  input, select, textarea { font-size: 16px; padding: 12px 13px; }

  /* ปุ่มต้องสูงพอให้นิ้วกดโดนง่าย (~44px) */
  button, .btn { min-height: 46px; }
  .btn-sm { min-height: 40px; padding: 8px 13px; font-size: 14px; }

  /* ---------- แถบบน: เหลือแค่โลโก้กับชื่อผู้ใช้ ---------- */
  .topbar { padding: 11px 14px; padding-top: calc(11px + env(safe-area-inset-top)); }
  .topbar nav, .desktop-only { display: none !important; }
  .topbar .who { margin-left: auto; font-size: 13px; }

  /* ---------- แถบเมนูล่าง ---------- */
  body.has-bottomnav { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .bottomnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    background: var(--bg-soft);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a, .bottomnav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 56px;
    padding: 5px 2px;
    background: none;
    border: none;
    border-radius: 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  .bottomnav a.active, .bottomnav button.active { color: var(--brand); }
  .bottomnav .bn-ico { font-size: 21px; line-height: 1.2; }
  /* ปุ่มสแกนใหญ่ตรงกลาง ใช้บ่อยที่สุด */
  .bottomnav .bn-scan {
    flex: 0 0 72px;
    margin-top: -24px;
    min-height: 72px;
    border-radius: 50%;
    background: var(--brand);
    color: #22150a !important;
    box-shadow: 0 6px 18px rgba(255, 138, 31, 0.4);
    justify-content: center;
    border: 4px solid var(--bg);
  }
  .bottomnav .bn-scan .bn-ico { font-size: 25px; }

  /* ---------- กล่องหน้าต่าง: เลื่อนขึ้นจากด้านล่างแบบแอปมือถือ ---------- */
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .modal-actions { position: sticky; bottom: -20px; background: var(--card); padding-top: 12px; margin-bottom: -8px; }
  .modal-actions button { flex: 1; }

  .sheet-bg { display: flex; z-index: 70; }
  .sheet-bg[hidden] { display: none; }
  .sheet { padding-top: 14px; }
  .sheet-user { padding: 6px 4px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; font-weight: 600; }
  .sheet-link {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 54px;
    padding: 0 12px;
    border-radius: 12px;
    color: var(--text);
    font-size: 17px;
    font-weight: 500;
    background: none;
    justify-content: flex-start;
  }
  .sheet-link:hover, .sheet-link.active { background: var(--card-2); }
  .sheet-logout { color: var(--red); margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0; }

  /* แจ้งเตือนย้ายไปด้านบน ไม่ให้บังปุ่มของกล่องที่เลื่อนขึ้นจากล่าง หรือแถบเมนูล่าง */
  /* ปุ่มเลือกประเภทงานในหน้าสแกน: ให้ข้อความอยู่บรรทัดเดียว */
  .mode-tabs { gap: 6px; }
  .mode-tabs button { padding: 11px 4px; font-size: 15px; white-space: nowrap; }

  #toast {
    top: calc(10px + env(safe-area-inset-top));
    bottom: auto;
    width: calc(100% - 24px);
    transform: translateX(-50%) translateY(-160%);
  }
  #toast.show { transform: translateX(-50%) translateY(0); }

  /* ---------- ตาราง → การ์ด ----------
     ตารางกว้างๆ บนจอมือถือต้องเลื่อนด้านข้าง จึงจัดแต่ละแถวใหม่เป็นการ์ด
     ตำแหน่งของแต่ละช่องกำหนดด้วย class ของ td */
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr {
    display: grid;
    gap: 3px 12px;
    align-items: center;
    padding: 13px 2px;
    border-bottom: 1px solid var(--line);
  }
  table.cards tbody tr:hover { background: none; }
  table.cards td { padding: 0; border: none; min-width: 0; }
  table.cards td.empty { grid-column: 1 / -1; }
  table.cards .m-hide { display: none; }
  table.cards .m-only { display: inline; }
  table.cards .m-sub { color: var(--muted); font-size: 14px; }

  /* รายการอะไหล่ */
  table.cards-parts tr {
    grid-template-columns: 56px 1fr auto;
    grid-template-areas: 'img name qty' 'img code qty' 'img loc loc' 'act act act';
  }
  .cards-parts .c-img { grid-area: img; align-self: start; }
  .cards-parts .c-img .thumb { width: 56px; height: 56px; }
  .cards-parts .c-name { grid-area: name; font-weight: 600; }
  .cards-parts .c-code { grid-area: code; color: var(--muted); font-size: 14px; }
  .cards-parts .c-code b { color: var(--brand); }
  .cards-parts .c-loc { grid-area: loc; color: var(--muted); font-size: 14px; }
  .cards-parts .c-loc::before { content: '🗄️ ชั้น '; }
  .cards-parts .c-qty { grid-area: qty; text-align: right; }
  .cards-parts .c-qty .badge { font-size: 14px; padding: 6px 11px; }
  .cards-parts .c-act { grid-area: act; display: flex; gap: 8px; margin-top: 9px; }
  .cards-parts .c-act > * { flex: 1; }

  /* ของใกล้หมดในหน้าภาพรวม */
  table.cards-low tr {
    grid-template-columns: 1fr auto;
    grid-template-areas: 'name qty' 'code min' 'act act';
  }
  .cards-low .c-name { grid-area: name; font-weight: 600; }
  .cards-low .c-code { grid-area: code; color: var(--muted); font-size: 14px; }
  .cards-low .c-min { grid-area: min; text-align: right; color: var(--muted); font-size: 13px; }
  .cards-low .c-min::before { content: 'จุดสั่งซื้อ '; }
  .cards-low .c-qty { grid-area: qty; text-align: right; }
  .cards-low .c-act { grid-area: act; margin-top: 8px; }
  .cards-low .c-act .btn { width: 100%; }

  /* ประวัติการเคลื่อนไหว */
  table.cards-moves tr {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: 'type part qty' 'time time after' 'who who who' 'note note note';
  }
  .cards-moves .h-type { grid-area: type; }
  .cards-moves .h-part { grid-area: part; font-size: 15px; }
  .cards-moves .h-qty { grid-area: qty; text-align: right; font-weight: 700; font-size: 18px; }
  .cards-moves .h-time { grid-area: time; color: var(--muted); font-size: 13px; }
  .cards-moves .h-after { grid-area: after; text-align: right; color: var(--muted); font-size: 13px; }
  .cards-moves .h-after::before { content: 'เหลือ '; }
  .cards-moves .h-who { grid-area: who; color: var(--muted); font-size: 13px; }
  .cards-moves .h-note { grid-area: note; color: var(--muted); font-size: 13px; }
  .cards-moves .h-note:empty { display: none; }

  /* ตารางทั่วไป (ชั้นวาง/ผู้ใช้): แต่ละช่องเป็นบรรทัด มีหัวข้ออยู่ซ้าย */
  table.cards-list tr { grid-template-columns: 1fr; }
  .cards-list td[data-label] { display: flex; justify-content: space-between; gap: 12px; }
  .cards-list td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 14px; }
  .cards-list td.c-title { font-size: 17px; font-weight: 700; }
  .cards-list td.c-act { display: flex; gap: 8px; margin-top: 8px; }
  .cards-list td.c-act > * { flex: 1; }
}

@media (max-width: 420px) {
  .grid.cols-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 13px; }
  .stat .value { font-size: 22px; }
  .row > * { min-width: 100%; }

  /* แถวที่ต้องอยู่บรรทัดเดียวกันเสมอ เช่น ช่องค้นหา+ปุ่ม, ยืนยัน+ยกเลิก */
  .row.inline > * { min-width: 0; }
  .row.inline > input { flex: 1; }

  /* กล่องตัวกรอง: ช่องค้นหาเต็มแถว ตัวเลือกย่อยวางคู่กัน ไม่ให้กินจอครึ่งหน้า */
  .row.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .row.filters > * { min-width: 0; }
  .row.filters > .f-full { grid-column: 1 / -1; }
  .row.filters .f-btns > * { flex: 1; }
}

/* ===== การ์ดพื้นที่ดิสก์ในหน้าภาพรวม ===== */
.disk-card { padding: 14px 18px; }
.disk-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 9px; }
.disk-head > span { color: var(--muted); }
.meter { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--green); }
.disk-card.low { border-color: var(--red); }
.disk-card.low .meter > span { background: var(--red); }
.disk-sub { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ===== หน้ารับสินค้า ===== */
.step-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 14px; }
.step-no {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #22150a; font-size: 15px;
}
.photo-box-lg { width: 100%; height: auto; aspect-ratio: 4 / 3; font-size: 48px; }
.photo-box-lg small { font-size: 15px; }
.result-card { text-align: center; border-color: var(--green); }
.result-ok { color: var(--green); font-weight: 800; font-size: 18px; margin-bottom: 14px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; }
.result-photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.result-qr { padding: 10px; }
.result-qr img { max-width: 100%; }
.place-to {
  display: inline-block; margin-top: 4px; padding: 10px 16px; border-radius: 12px;
  background: rgba(74, 158, 255, 0.14); color: var(--text); font-size: 17px;
}
.place-to span { color: var(--muted); font-size: 14px; }

/* ===== หน้าสแกน: การ์ดสินค้าชิ้นเดียว ===== */
.item-card { text-align: center; }
.item-card .item-photo { width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; background: var(--bg); }
.item-status { display: inline-block; margin: 12px 0 6px; padding: 6px 14px; border-radius: 999px; font-weight: 700; }
.item-status.in { background: rgba(47, 191, 113, 0.18); color: var(--green); }
.item-status.out { background: rgba(239, 77, 77, 0.18); color: var(--red); }
.btn-issue { font-size: 19px; padding: 16px; }

/* ===== รายการชิ้น (หน้าสินค้า / คิวพิมพ์) ===== */
.unit-list { display: grid; gap: 10px; }
.unit {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-2);
}
.unit img.thumb, .unit .thumb { width: 64px; height: 64px; }
.unit .u-id { font-weight: 800; color: var(--brand); }
.unit .u-meta { color: var(--muted); font-size: 13px; }
.unit.out { opacity: 0.55; }
.unit-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ===== แถบเตือนรอพิมพ์ QR ในหน้าภาพรวม ===== */
.print-alert {
  display: block; color: var(--text); border-color: var(--yellow);
  background: rgba(245, 197, 66, 0.1); font-size: 16px;
}
.print-alert span { color: var(--muted); }

/* เลื่อนไปหาผลสแกนแล้วต้องไม่มุดใต้แถบบนที่ติดหน้าจอ (sticky) */
#resultBox, #partCard, #locCard { scroll-margin-top: calc(76px + env(safe-area-inset-top)); }

/* มือถือ: ปุ่มของแต่ละชิ้นลงไปอยู่แถวล่าง ไม่เบียดรายละเอียดจนเหลือคำละบรรทัด */
@media (max-width: 620px) {
  .unit.with-actions { grid-template-columns: 56px 1fr; }
  .unit.with-actions img.thumb, .unit.with-actions .thumb { width: 56px; height: 56px; }
  .unit.with-actions .unit-actions { grid-column: 1 / -1; justify-content: stretch; }
  .unit.with-actions .unit-actions > * { flex: 1; white-space: nowrap; padding-left: 6px; padding-right: 6px; }
}

/* ===== ช่องเลือก + ปุ่ม "+ เพิ่ม" ข้างกัน (หมวดหมู่ / ชั้นวาง) ===== */
.select-add { display: flex; gap: 8px; }
.select-add select { flex: 1; min-width: 0; }
.select-add button { flex: 0 0 auto; white-space: nowrap; }

/* ===== รูปหลายรูปของ 1 ชิ้น (หน้ารับของ) ===== */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 12px; }
.photo-grid .ph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--bg); }
.photo-grid .ph img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo-grid .ph .ph-del {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; min-height: 0; padding: 0;
  border-radius: 50%; background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 15px;
}
.photo-grid .ph .ph-cover {
  position: absolute; left: 4px; bottom: 4px; padding: 2px 7px; border-radius: 6px;
  background: var(--brand); color: #22150a; font-size: 11px; font-weight: 700;
}
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-buttons button { min-height: 56px; font-size: 16px; }

/* ===== แถบรูปเล็กแนวนอน (แตะเพื่อดูใหญ่) ===== */
.thumb-strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scroll-snap-type: x mandatory; }
.thumb-strip img {
  flex: 0 0 auto; width: 72px; height: 72px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); cursor: zoom-in; scroll-snap-align: start;
}
.thumb-strip.big img { width: 120px; height: 120px; }

/* ===== ดูรูปใหญ่เต็มจอ ปัดซ้าย-ขวา ===== */
.gallery { position: fixed; inset: 0; z-index: 300; background: rgba(0, 0, 0, 0.92); }
.gallery-track { display: flex; width: 100%; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery-slide { flex: 0 0 100%; height: 100%; display: flex; align-items: center; justify-content: center; scroll-snap-align: center; padding: 16px; }
.gallery-slide img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.gallery-count { position: absolute; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); color: #fff; font-weight: 700; }
.gallery-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 46px; height: 46px; min-height: 0; padding: 0;
  border-radius: 50%; background: rgba(255, 255, 255, 0.15); color: #fff; font-size: 20px;
}

/* ===== รูปในหน้าต่างเพิ่มชั้นวาง ===== */
.photo-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.photo-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* ===== รูปชั้นวาง: บอกว่าต้องไปวาง/ไปหยิบตรงไหน ===== */
.shelf-hint { display: flex; gap: 10px; align-items: center; margin-top: 10px; text-align: left; }
.shelf-hint img { width: 84px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; flex: 0 0 auto; }
.shelf-hint .sh-text { color: var(--muted); font-size: 14px; }
.shelf-hint .sh-text b { color: var(--text); font-size: 16px; }

/* ===== ยืนยันก่อนเบิก ===== */
.confirm-box {
  margin-top: 14px; padding: 14px; border-radius: 14px; text-align: left;
  border: 2px solid var(--yellow); background: rgba(245, 197, 66, 0.08);
}
.confirm-box .cf-title { font-weight: 800; font-size: 17px; margin-bottom: 6px; }
.confirm-box .cf-line { color: var(--muted); font-size: 14px; margin: 2px 0; }
.confirm-box .cf-line b { color: var(--text); }
.confirm-box .row { margin-top: 12px; }

/* ===== โลโก้ RST Truck Parts ที่แถบบน ===== */
.topbar .logo { color: var(--text); text-decoration: none; }
.topbar .logo img { height: 40px; width: auto; display: block; }
.topbar .logo .logo-sub {
  font-size: 13px; font-weight: 800; letter-spacing: 2px; color: var(--muted);
  border-left: 1px solid var(--line); padding-left: 9px;
}
@media (max-width: 768px) {
  .topbar .logo img { height: 36px; }
}

/* ===== ให้ความรู้สึกเป็นแอป: ห้ามซูม ห้ามปัดทั้งหน้าไปซ้าย-ขวา =====
   pan-y = เลื่อนได้แค่ขึ้น-ลง ไม่มีบีบนิ้วซูม ไม่มีแตะสองครั้งซูม
   ส่วนที่ต้องปัดข้างได้ (แถบรูป ดูรูปใหญ่ ตาราง เมนูบน) เปิดให้ปัดซ้าย-ขวาเฉพาะในกรอบนั้น */
html, body { overflow-x: hidden; max-width: 100%; overscroll-behavior-x: none; }
html { touch-action: pan-y; }
.gallery-track, .thumb-strip, .table-wrap, .topbar nav { touch-action: pan-x pan-y; }

/* ===== ปุ่มเลือกหมวด/ชั้น ในหน้าสินค้า ===== */
.chip-group { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 10px 16px;
  background: var(--card-2); color: var(--text); border: 1px solid var(--line); border-radius: 14px; font-size: 16px; font-weight: 600;
}
.chip:hover { background: var(--line); }
.chip span { background: var(--bg); color: var(--muted); border-radius: 999px; padding: 2px 9px; font-size: 13px; }
.chip-warn { border-color: var(--yellow); color: var(--yellow); }

/* ปุ่มแท็บที่ข้อความยาว (หน้าพิมพ์ QR) ให้ขึ้นบรรทัดใหม่ได้ ไม่ล้นจอ */
.mode-tabs.mode-tabs-wrap button { white-space: normal; line-height: 1.3; }
