/* ระบบสต๊อกหน้าร้าน — ออกแบบให้ใช้บนมือถือเป็นหลัก ปุ่มใหญ่ กดง่าย */

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e2e6ea;
  --text: #1b232b;
  --muted: #6b7683;
  --brand: #0b6bcb;
  --brand-dark: #08549f;
  --ok: #17864a;
  --ok-bg: #e6f5ec;
  --warn: #b45309;
  --warn-bg: #fdf3e3;
  --danger: #c02626;
  --danger-bg: #fdeaea;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

/* ── โครงหน้า ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--brand); color: #fff;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; flex: 1; min-width: 0; }
.topbar h1 .brand { display: block; line-height: 1.2; }
.topbar h1 .sub2 { display: block; font-size: 12px; font-weight: 400; opacity: .85; line-height: 1.3; }
.topbar .who { font-size: 13px; opacity: .9; text-align: right; line-height: 1.25; }
.topbar a, .topbar button.link {
  color: #fff; font-size: 13px; text-decoration: none;
  border: 1px solid rgba(255,255,255,.5); border-radius: 8px;
  padding: 5px 10px; background: transparent; cursor: pointer; white-space: nowrap;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 12px 12px 96px; }
.wide { max-width: 1200px; }

/* ── แท็บ ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 48px; z-index: 20; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.tabs button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

.panel { display: none; }
.panel.on { display: block; }

/* ── การ์ด ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
.card h2 .sub { font-weight: 400; color: var(--muted); font-size: 13px; }

/* ── ฟอร์ม ────────────────────────────────────────────────────────────────── */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea, button { font-family: inherit; font-size: 16px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,107,203,.35); outline-offset: 0; border-color: var(--brand); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; min-width: 0; }
.field { margin-bottom: 10px; }

button.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; background: var(--brand); color: #fff;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
button.btn:hover { background: var(--brand-dark); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.btn.danger { background: var(--danger); }
button.btn.ok { background: var(--ok); }
button.btn.sm { padding: 7px 12px; font-size: 14px; }
button.btn.full { width: 100%; }

/* ── ตัวกรอง/ชิป ──────────────────────────────────────────────────────────── */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chips button.on { background: #e8f1fc; border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* ── รายการสินค้าให้เลือก ──────────────────────────────────────────────────── */
.picklist { max-height: 48vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.pickrow {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: #fff;
}
.pickrow:last-child { border-bottom: 0; }
.pickrow:hover { background: #f7fafd; }
.pickrow .nm { flex: 1; min-width: 0; }
.pickrow .nm b { font-weight: 500; display: block; }
.pickrow .nm small { color: var(--muted); font-size: 12px; }
.pickrow .stk { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.pickrow .stk b { display: block; font-size: 16px; color: var(--text); }
.pickrow.picked { background: #eef6ff; }
.pickrow .qtybadge { font-size: 15px; font-weight: 700; color: var(--brand); min-width: 44px; text-align: right; }

/* ── ตะกร้าบิล ────────────────────────────────────────────────────────────── */
.lines { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.line {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); background: #fff;
}
.line:last-child { border-bottom: 0; }
.line .nm { flex: 1; min-width: 0; font-size: 14px; }
.line .nm small { display: block; color: var(--muted); font-size: 12px; }
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stepper button {
  width: 38px; height: 38px; border: 0; background: #f3f5f7; font-size: 20px;
  cursor: pointer; color: var(--text); line-height: 1;
}
.stepper button:hover { background: #e8ebee; }
.stepper input {
  width: 58px; height: 38px; border: 0; border-left: 1px solid var(--line);
  border-right: 1px solid var(--line); text-align: center; border-radius: 0; padding: 0;
  font-size: 16px; font-weight: 600;
}
.line .del { border: 0; background: transparent; color: var(--danger); font-size: 20px; cursor: pointer; padding: 0 6px; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 14px; }

/* ── ปุ่มเลือกแบบสองตัวเลือก (ประเภทบิล / วิธีชำระเงิน) ────────────────────── */
.req { color: var(--danger); font-weight: 700; }
.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; border-right: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 10px 8px; font-size: 15px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
/* กว้างพอให้ข้อความอย่าง "ใบกำกับภาษี / บิลเงินสด" ไม่โดนตัด บนจอแคบจะตกลงมาคนละบรรทัด */
.row > .segfield { flex: 1 1 250px; }
.seg button:hover { background: #f5f8fb; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
.seg.invalid { border-color: var(--danger); }

/* ── ตารางกรอกยอดเงินตอนปิดยอด ────────────────────────────────────────────── */
.moneygrid { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; }
.moneygrid label { margin: 0; font-size: 15px; color: var(--text); }
.moneygrid input { width: 140px; text-align: right; font-variant-numeric: tabular-nums; }
.moneygrid .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin: -4px 0 4px; }
.moneygrid .sep { grid-column: 1 / -1; border-top: 1px dashed var(--line); margin: 6px 0; }
.moneyrow-bad input { border-color: var(--danger); background: #fff7f7; }
.moneyrow-ok input { border-color: #b9e2c9; }

/* ── ตาราง ────────────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f7f9fb; font-weight: 600; font-size: 13px; color: var(--muted); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap-cell { white-space: normal; min-width: 180px; }

/* ── ป้ายสถานะ ────────────────────────────────────────────────────────────── */
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--danger-bg); color: var(--danger); }
.tag.mute { background: #eef1f4; color: var(--muted); }

/* ── ตัวเลขสรุป ───────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; font-weight: 400; color: var(--muted); }

/* ── แถบเครื่องมือล่างจอ ──────────────────────────────────────────────────── */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: #fff; border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 -2px 10px rgba(16,24,40,.06);
}
.bottombar .info { flex: 1; font-size: 13px; color: var(--muted); line-height: 1.3; }
.bottombar .info b { display: block; font-size: 16px; color: var(--text); }

/* ── ข้อความแจ้งเตือน ─────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: #1b232b; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: 90vw; text-align: center; opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.notice { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d9b0; }
.notice.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #b9e2c9; }
.notice.bad { background: var(--danger-bg); color: var(--danger); border: 1px solid #f2c2c2; }

/* ── หน้าล็อกอิน ──────────────────────────────────────────────────────────── */
.loginwrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.loginbox { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 26px 22px; box-shadow: 0 8px 30px rgba(16,24,40,.10); }
.loginbox h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.loginbox p.sub { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* ── หน้าต่างซ้อน ─────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.5); z-index: 50; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.on { display: flex; }
.modal .box { background: #fff; border-radius: 14px; padding: 18px; width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto; }
.modal .box h3 { margin: 0 0 12px; font-size: 17px; }

/* ── กราฟแท่งอย่างง่าย ────────────────────────────────────────────────────── */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 6px; }
.bars .b { flex: 1; background: #cfe1f5; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .b.has { background: var(--brand); }
.bars .b.missing { background: #f3c9c9; }
.barlabels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.mt { margin-top: 12px; }
.hide { display: none !important; }

@media (max-width: 480px) {
  .wrap { padding: 10px 10px 100px; }
  .stat .v { font-size: 20px; }
  /* ชื่อสาขายาว ถ้าไม่ย่อจะดันแถบบนสูงจนกินพื้นที่หน้าจอ */
  .topbar { padding: 8px 10px; gap: 8px; }
  .topbar h1 { font-size: 14px; }
  .topbar h1 .sub2 { font-size: 11px; }
  .topbar .who { font-size: 11px; }
  .topbar a, .topbar button.link { font-size: 12px; padding: 4px 8px; }
}
