/* Boss Carton งานผลิต — มือถือเป็นหลัก ใช้งานหน้าลานโหลดของ */

@font-face {
  font-family: "Plex Thai";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-thai-thai-400-normal.woff2") format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Plex Thai";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-thai-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex Thai";
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-thai-thai-600-normal.woff2") format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Plex Thai";
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-thai-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #000;            /* หมึกดำ K100 แบบพิมพ์บนกล่อง */
  --paper: #eef0ec;       /* ผิวกระดาษเคลือบขาว */
  --sheet: #fff;
  --kraft: #c49a5b;       /* กระดาษคราฟท์ */
  --kraft-deep: #7a5a2e;
  --muted: #565a52;
  --line: #c9ccc4;
  --go: #1f6b3a;          /* ขึ้นรถแล้ว / ยืนยัน */
  --stop: #b42318;        /* มีปัญหา */
  --lock: #2f4f6f;        /* ออกใบส่งสินค้าแล้ว */
  --wait: #8a6d1f;        /* รอขึ้นรถ */
  --radius-s: 6px;
  --radius-m: 10px;
  --tap: 52px;
  font-family: "Plex Thai", "Thonburi", "Noto Sans Thai", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-size: 17px;
  line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* แถบหัวแบบลอนลูกฟูก — จุดเดียวที่ตั้งใจให้จำได้ */
.band {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background:
    repeating-linear-gradient(90deg, rgba(122, 90, 46, .22) 0 2px, transparent 2px 9px),
    var(--kraft);
  border-bottom: 3px solid var(--kraft-deep);
  display: flex;
  align-items: center;
  gap: 12px;
}
.band__home {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.band__who { flex: 0 1 auto; min-width: 0; max-width: 46%; font-size: .9rem; text-align: right; line-height: 1.25; }
.band__name, .band__who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band__who small { color: #2c2416; }
.band__out {
  flex: none;
  white-space: nowrap;
  min-height: 40px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
  background: transparent;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink);
}

/* มือถือ: หัวแอปบรรทัดเดียว ไม่ตัดคำกลางชื่อ */
@media (max-width: 480px) {
  .band { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .band__long { display: none; }
  .band__who { font-size: .8rem; max-width: 44%; }
  .band__out { min-height: 36px; padding: 0 10px; font-size: .82rem; }
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px 48px;
  outline: none;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 600; margin-top: 28px; margin-bottom: 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

a { color: var(--ink); text-underline-offset: 3px; }

:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }
/* พื้นที่เนื้อหารับโฟกัสตอนเปลี่ยนหน้า (ให้โปรแกรมอ่านหน้าจออ่านต่อได้) แต่ไม่ต้องมีกรอบสีน้ำเงิน */
main:focus, main:focus-visible { outline: none; }

/* ปุ่ม */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-m);
  line-height: 1.3;
  text-align: center;
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--go { background: var(--go); border-color: var(--go); color: #fff; }
.btn--stop { color: var(--stop); border-color: var(--stop); }
.btn--ink { background: var(--ink); color: #fff; }
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.btn-row > .btn:only-child { grid-column: 1 / -1; }
.stack { display: grid; gap: 10px; margin-top: 16px; }

/* หน้าเข้าสู่ระบบ */
.login { padding-top: 12vh; }
.login h1 { font-size: 2rem; }
.login .btn { margin-top: 28px; }
.alert {
  border-left: 5px solid var(--stop);
  background: #fff;
  padding: 12px 14px;
  margin-top: 18px;
}

/* รายการ tag */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rows > li { border-bottom: 1px solid var(--line); }
.row-link {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 14px 4px;
  color: inherit;
  text-decoration: none;
}
.row-link strong { font-size: 1.1rem; }
.row-link .meta { grid-column: 1 / -1; color: var(--muted); font-size: .92rem; }
.count { font-weight: 600; white-space: nowrap; }
.bar { grid-column: 1 / -1; height: 8px; background: #dfe2db; border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--go); }

/* หน้างาน: เลข JB ใหญ่แบบพิมพ์บนกล่อง */
.jb {
  font-size: clamp(2.1rem, 9vw, 3rem);
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.05;
  margin: 4px 0 6px;
  word-break: break-all;
}
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

/* รายการขึ้นรถ */
.line {
  background: var(--sheet);
  border-left: 6px solid var(--wait);
  padding: 14px 14px 16px;
  margin-top: 12px;
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
}
.line--loaded { border-left-color: var(--go); }
.line--locked { border-left-color: var(--lock); }
.line--issue { border-left-color: var(--stop); }
.line__head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.line__no { font-size: 1.25rem; font-weight: 600; }
.line__qty { font-weight: 600; white-space: nowrap; }
.status { margin-top: 6px; font-weight: 600; }
.status--wait { color: var(--wait); }
.status--loaded { color: var(--go); }
.status--locked { color: var(--lock); }
.issue-note { margin-top: 6px; color: var(--stop); font-weight: 600; }

/* เอกสาร และ ประวัติ */
.docs { list-style: none; padding: 0; margin: 0; }
.docs li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.docs .btn { width: auto; min-height: 44px; }
.log { list-style: none; padding: 0; margin: 0; font-size: .95rem; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); display: block; font-size: .85rem; }

/* สแกน */
#reader { width: 100%; max-width: 480px; margin: 12px auto 0; background: #000; border-radius: var(--radius-m); overflow: hidden; min-height: 260px; }

/* จัดการบัญชี */
.form { display: grid; gap: 10px; background: var(--sheet); padding: 14px; border-radius: var(--radius-m); margin-top: 10px; }
label { display: grid; gap: 4px; font-weight: 600; font-size: .95rem; }
input, select, textarea {
  font: inherit;
  font-size: 17px;        /* ต่ำกว่า 16px แล้ว iPhone จะซูมหน้าตอนพิมพ์และค้างซูม */
  font-weight: 400;
  min-height: 46px;
  padding: 8px 10px;
  border: 2px solid #9aa094;
  border-radius: var(--radius-s);
  background: #fff;
  color: var(--ink);
  width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
.person { background: var(--sheet); padding: 12px 14px; margin-top: 10px; border-radius: var(--radius-s); }
.person--off { opacity: .6; }
.person__top { display: flex; justify-content: space-between; gap: 10px; }
.person__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.person__actions .btn { min-height: 44px; font-size: .95rem; }

/* หน้าต่างยืนยัน */
dialog {
  border: none;
  border-radius: var(--radius-m);
  padding: 20px 18px 18px;
  width: min(92vw, 460px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin-top: 0; }

/* แจ้งผล */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateX(-50%);
  max-width: 92vw;
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-m);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 20;
}
.toast--show { opacity: 1; }
.toast--bad { background: var(--stop); }

.loading { padding: 40px 0; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
