/* ---------- tokens ---------- */
:root {
  --ground: #EEF1F4; --ink: #1A1F26; --sub: #3B4652; --muted: #56616E;
  --line: #D5DCE3; --line2: #E3E8ED; --field: #C3CCD5; --white: #FFFFFF;
  --act: #C2410C; --act-tint: #FCEBE2; --act-ink: #9A3412;
  --info: #1F5A8A; --info-tint: #E3EEF7; --info-ink: #153F61;
  --ok: #1D5B33; --ok-tint: #E4F1E8;
  --warn: #7A4A0E; --warn-tint: #FDF0DD;
  --out: #8A2A12; --out-tint: #FCE7E2;
  --bar: #1A1F26;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, sans-serif; font-size: 15px; line-height: 1.6;
}
button, input, select { font-family: inherit; font-size: 14px; color: var(--ink); }
a { color: var(--info); }
a:hover { color: var(--info-ink); }
h1 { margin: 0; font-size: 24px; font-weight: 700; line-height: 1.4; }
h2 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.4; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--act); outline-offset: 2px; }
main:focus { outline: none; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--white); padding: 10px 14px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }

/* ---------- top bar ---------- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 6px 24px; min-height: 60px; }
.top.staff { background: var(--bar); color: var(--white); }
.top.cust { background: var(--white); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; margin-right: 12px; }
.top nav { display: flex; flex-wrap: wrap; gap: 4px; }
.top nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 8px;
  font-size: 15px; text-decoration: none;
}
.staff nav a { color: #DCE3EA; }
.staff nav a:hover { background: #2B333D; color: var(--white); }
.staff nav a[aria-current="page"] { background: var(--act); color: var(--white); font-weight: 600; }
.cust nav a { color: var(--info); }
.cust nav a:hover { background: var(--info-tint); }
.cust nav a[aria-current="page"] { background: var(--act-tint); color: var(--act-ink); font-weight: 600; }
.who { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; }
.staff .who { color: #B8C4CF; }
.cust .who { color: var(--sub); }
.who .btn-quiet { min-height: 44px; padding: 0 12px; border-radius: 8px; background: transparent; cursor: pointer; font-size: 13px; }
.staff .who .btn-quiet { color: var(--white); border: 1px solid #56616E; }
.cust .who .btn-quiet { color: var(--ink); border: 1px solid var(--field); }

/* ---------- layout ---------- */
.wrap { padding: 24px; display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; max-width: 1400px; width: 100%; margin: 0 auto; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.col-side { flex: 1 1 320px; min-width: 0; }
.stack { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.narrow { max-width: 720px; margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row h1 { flex: 1 1 200px; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.foot { max-width: 1400px; width: 100%; margin: 0 auto; padding: 8px 24px 32px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.foot p { flex: 1 1 300px; }

/* ---------- controls ---------- */
.btn, .btn-primary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--field); background: var(--white); color: var(--ink);
  font-size: 14px; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:hover { background: #F6F8FA; color: var(--ink); }
.btn-primary { background: var(--act); border-color: var(--act); color: var(--white); font-weight: 600; }
.btn-primary:hover { background: #A8370A; color: var(--white); }
.btn[disabled], .btn-primary[disabled] { opacity: .45; cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 22px; font-size: 14px; cursor: pointer;
  border: 1px solid var(--field); background: var(--white);
}
.chip[aria-pressed="true"] { border-color: var(--act); background: var(--act-tint); }
.search {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--field); border-radius: 10px; background: var(--white);
  padding: 0 12px; min-height: 44px; flex: 0 1 280px;
}
.search input { flex: 1; min-width: 0; border: 0; min-height: 42px; background: transparent; }
.search input:focus-visible { outline: none; }
.search:focus-within { outline: 2px solid var(--act); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .field > label { font-size: 13px; color: var(--sub); font-weight: 500; }
.field input, .field select {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 10px; background: var(--white); width: 100%;
}
.field input[disabled] { background: var(--ground); color: var(--muted); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.msg { font-size: 14px; padding: 10px 12px; border-radius: 8px; }
.msg.err { background: var(--out-tint); color: var(--out); }
.msg.ok { background: var(--ok-tint); color: var(--ok); }
.msg.info { background: var(--info-tint); color: var(--info-ink); }
.msg ul { margin: 0; padding-left: 20px; }
.calc { font-size: 14px; padding: 10px 12px; border-radius: 8px; background: var(--info-tint); color: var(--info-ink); min-height: 44px; display: flex; align-items: center; }

/* ---------- tables ---------- */
.tbl { background: var(--white); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.tbl table { width: 100%; border-collapse: collapse; min-width: var(--minw, 720px); }
.tbl th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.tbl td { padding: 10px 16px; font-size: 14px; border-bottom: 1px solid var(--ground); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl .c { text-align: center; }
.tbl td.num { text-align: right; font-family: var(--mono); }
.tbl td a.sku { display: inline-flex; align-items: center; min-height: 44px; font-family: var(--mono); font-size: 13px; }
.cellname { display: flex; flex-direction: column; gap: 2px; }
.cellname b { font-weight: 600; }
.cellname small { font-size: 12px; color: var(--muted); }
.res { color: var(--act-ink); }
.in { color: var(--ok); }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 12px; white-space: nowrap; line-height: 1.6; }
.pill.ok { background: var(--ok-tint); color: var(--ok); }
.pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.out { background: var(--out-tint); color: var(--out); }
.pill.info { background: var(--info-tint); color: var(--info-ink); }
.pill.res { background: var(--act-tint); color: var(--act-ink); }
.pill.neutral { background: var(--ground); color: var(--sub); }

/* ---------- request cards ---------- */
.rq { border: 1px solid var(--line2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.rq-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.rq-no { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.rq-items { font-size: 13px; color: var(--sub); }
.rq-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rq-actions .btn-primary { flex: 1 1 140px; }
.count { font-family: var(--mono); font-size: 14px; color: var(--act); font-weight: 700; }
.steps { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.steps li { font-size: 11px; text-align: center; padding: 6px 2px; border-radius: 6px; background: var(--ground); color: var(--muted); line-height: 1.5; }
.steps li.on { background: var(--info); color: var(--white); }
.note-out { font-size: 13px; color: var(--out); }

/* ---------- cart stepper ---------- */
.stepper { display: flex; align-items: center; justify-content: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--field); background: var(--white); font-size: 18px; cursor: pointer; }
.stepper button[disabled] { opacity: .4; cursor: not-allowed; }
.stepper input { width: 72px; min-height: 44px; text-align: center; font-family: var(--mono); font-weight: 600; border: 1px solid var(--field); border-radius: 10px; }
.stepper input[aria-invalid="true"] { border-color: var(--out); background: var(--out-tint); }
.rowerr { font-size: 12px; color: var(--out); margin-top: 2px; }
.submitbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.submitbar .cart-text { flex: 1 1 260px; font-size: 14px; color: var(--sub); }
.submitbar .btn-primary { min-height: 48px; padding: 0 22px; font-size: 15px; }

/* ---------- card page ---------- */
.cardtop { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.cardtop > .panel { padding: 18px; gap: 6px; }
.cardtop .info { flex: 2 1 360px; }
.cardtop .nums { flex: 1 1 360px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: center; }
.big { display: flex; flex-direction: column; gap: 2px; }
.big span:first-child { font-size: 13px; color: var(--muted); }
.big span:last-child { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.lock { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--warn-tint); color: var(--warn); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; }
.login-box { margin: auto; width: 100%; max-width: 520px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.roles { display: grid; gap: 10px; }
.role { text-align: left; min-height: 64px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--field); background: var(--white); cursor: pointer; display: flex; flex-direction: column; justify-content: center; gap: 0; }
.role:hover { border-color: var(--act); background: var(--act-tint); }
.role b { font-size: 16px; font-weight: 600; }
.role small { font-size: 13px; color: var(--muted); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); z-index: 60; pointer-events: none; }
#toast .t { padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--white); font-size: 14px; box-shadow: 0 4px 16px rgba(26, 31, 38, .25); }
#toast .t.err { background: var(--out); }

/* ---------- phone ---------- */
@media (max-width: 640px) {
  .top { padding: 6px 16px; }
  .wrap, .stack { padding: 16px; }
  .foot { padding: 8px 16px 32px; }
  h1 { font-size: 22px; }
  .search { flex: 1 1 100%; }
  .big span:last-child { font-size: 22px; }
  .who { margin-left: 0; width: 100%; }
  /* cart rows stack as cards so the stepper is never hidden off-screen */
  .tbl.cart table { min-width: 0; }
  .tbl.cart thead { display: none; }
  .tbl.cart tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--ground); }
  .tbl.cart td { padding: 0; border: 0; }
  .tbl.cart td:nth-child(3) { grid-column: 1 / -1; }
  .tbl.cart .stepper { justify-content: flex-start; }
  .tbl.cart td.num::before { content: "เบิกได้ "; font-family: "Noto Sans Thai", sans-serif; font-size: 12px; color: var(--muted); }
}
