:root {
  --bg: #F3F4F1; --card: #FFFFFF; --ink: #16191D; --muted: #5A6169; --line: #DADDD8; --line2: #EDEFEA;
  --blue: #1F4FA8; --blue-bg: #E1E9F7; --blue-ink: #163A7D;
  --ok: #17734F; --ok-bg: #DDF0E6; --ok-ink: #0F5539;
  --warn: #A35400; --warn-bar: #E8A04A; --warn-bg: #FBEBD6; --warn-ink: #7A3F00;
  --idle: #E3E6E0; --dark: #16191D;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'IBM Plex Sans Thai', 'Noto Sans Myanmar', system-ui, sans-serif; font-size: 15px; line-height: 1.45; }
a { color: var(--blue); }
a:hover { color: var(--blue-ink); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.wrap { max-width: 1360px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 18px; }
.narrow { max-width: 560px; }

/* top bar */
.top { background: var(--dark); color: #fff; }
.top .in { max-width: 1360px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.top .brand { font-weight: 700; font-size: 17px; color: #fff; text-decoration: none; margin-right: auto; }
.top nav { display: flex; flex-wrap: wrap; gap: 4px; }
.top nav a { white-space: nowrap; color: #C9CDC6; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 15px; min-height: 44px; display: inline-flex; align-items: center; }
.top nav a.on { background: #2A2F35; color: #fff; font-weight: 600; }
.seg { display: inline-flex; border: 1px solid #3A4047; border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 14px; font-weight: 600; min-width: 48px; min-height: 40px; padding: 0 10px; border: 0; background: var(--dark); color: #C9CDC6; cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); }
.seg button:disabled { color: #6B7178; cursor: not-allowed; }

/* generic */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
h1 { font-size: 26px; margin: 0; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .grid3 { grid-template-columns: 1fr; } }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], input:not([type]) {
  font: inherit; font-size: 15px; color: var(--ink); background: #fff; border: 1px solid #C9CDC6; border-radius: 8px; padding: 0 10px; min-height: 44px; }
.btn { font: inherit; font-size: 15px; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid #C9CDC6; background: #fff; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.go { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.big { min-height: 60px; font-size: 18px; border-radius: 12px; width: 100%; }
.btn:disabled { background: var(--idle); border-color: var(--idle); color: var(--muted); cursor: not-allowed; }
.chip { display: inline-block; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 6px; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok-ink); }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.blue { background: var(--blue-bg); color: var(--blue-ink); }
.chip.idle { background: var(--idle); color: #3A4047; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 4px; background: var(--bg); color: #3A4047; }
.bar { height: 12px; border-radius: 3px; background: var(--idle); overflow: hidden; }
.bar > i { display: block; height: 100%; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.scroll { overflow-x: auto; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.msg { padding: 12px 14px; border-radius: 8px; font-weight: 600; }
.msg.ok { background: var(--ok-bg); color: var(--ok-ink); }
.msg.err { background: var(--warn-bg); color: var(--warn-ink); }
.hidden { display: none !important; }

/* monitor */
.kpi .lbl { font-size: 15px; color: var(--muted); }
.kpi .val { font-size: 40px; font-weight: 700; line-height: 1.15; }
.kpi .val small { font-size: 19px; color: var(--muted); font-weight: 500; }
.panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.pcard { display: flex; flex-direction: column; gap: 14px; text-decoration: none; color: var(--ink); }
.pcard:hover { border-color: #9BA3AB; color: var(--ink); }
.pcard .code { font-family: var(--mono); font-size: 19px; font-weight: 600; }
.steps5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.steps5 .n { font-size: 12px; font-weight: 600; color: #3A4047; line-height: 1.25; margin-top: 6px; }
.steps5 .v { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.cols { display: flex; flex-wrap: wrap; gap: 18px; }
.cols > .main { flex: 3 1 560px; min-width: 0; }
.cols > .side { flex: 2 1 340px; min-width: 0; }
.log { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
.log.void { opacity: .55; text-decoration: line-through; }

/* record */
.stepper { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stepbtn { font: inherit; text-align: left; border: 2px solid var(--line); border-radius: 10px; background: #fff; padding: 10px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; min-height: 72px; color: var(--ink); }
.stepbtn .t { font-weight: 700; font-size: 15px; }
.stepbtn .c { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.stepbtn.on { border-color: var(--blue); background: var(--blue-bg); }
.stepbtn.done { border-color: var(--ok-bg); }
.stepbtn:disabled { cursor: not-allowed; background: #F7F8F5; color: var(--muted); }
.qty { display: grid; grid-template-columns: 60px 1fr 60px; gap: 10px; }
.qty button { font-size: 28px; height: 60px; border: 1px solid #C9CDC6; border-radius: 10px; background: #fff; cursor: pointer; color: var(--ink); }
.qty input { height: 60px; text-align: center; font-family: var(--mono); font-size: 28px; font-weight: 600; width: 100%; }
.pin { text-align: center; font-size: 22px !important; letter-spacing: 8px; }
.results button { width: 100%; text-align: left; font: inherit; background: #fff; border: 0; border-bottom: 1px solid var(--line2); padding: 12px 4px; min-height: 52px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; color: var(--ink); }
.results button:hover { background: var(--bg); }
#scanBox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; }
#scanBox #reader { width: min(92vw, 420px); background: #000; }

/* labels */
.labels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.label { border: 1px dashed #C9CDC6; padding: 8px; display: grid; grid-template-columns: 96px 1fr; gap: 8px; align-items: center; height: 36mm; overflow: hidden; break-inside: avoid; }
.label img, .label canvas { width: 92px; height: 92px; }
.label .pn { font-family: var(--mono); font-weight: 600; font-size: 13px; word-break: break-all; }
.label .sm { font-size: 11px; color: #3A4047; }
@media print {
  .top, .noprint { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  @page { size: A4; margin: 8mm; }
}
.pcard .row { flex-wrap: nowrap; }
@media (max-width: 640px) {
  .top .in { padding: 8px 12px; gap: 6px 10px; }
  .top .seg { order: 2; }
  .top nav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .top nav a { padding: 8px 10px; }
  h1 { font-size: 22px; }
  .wrap { padding: 14px 12px 40px; gap: 14px; }
}
.panels { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
@media (max-width: 400px) { .panels { grid-template-columns: 1fr; } }
.steps5 .n { overflow-wrap: anywhere; }
.seg.light { border-color: #C9CDC6; }
.seg.light button { background: #fff; color: var(--ink); }
.seg.light button.on { background: var(--dark); color: #fff; }
@media screen and (max-width: 700px) { .labels { grid-template-columns: 1fr; } }
/* v3 scale tuning */
.narrow { max-width: 720px; }
.btn.big { min-height: 54px; font-size: 17px; }
@media (max-width: 640px) {
  body { font-size: 14px; }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
  .btn { min-height: 44px; font-size: 14px; padding: 0 12px; }
  .btn.big { min-height: 52px; font-size: 16px; }
  .card { padding: 12px 14px; }
  .kpi .val { font-size: 30px; }
  .top .brand { font-size: 15px; }
  .top nav a { font-size: 14px; min-height: 40px; }
  .seg button { min-height: 36px; min-width: 42px; font-size: 13px; }
}
