:root {
  --bg: #f6f4ee; --card: #ffffff; --ink: #1d231f; --muted: #6b716c; --line: #e3e0d7;
  --brand: #1f3d2b; --brand-ink: #ffffff; --accent: #8fae5a; --warn: #b7791f; --bad: #b42318; --ok: #2f7a3f;
  --chip: #eef0e6; --radius: 14px;
  font-family: "LINE Seed Sans TH", "LINE Seed Sans", -apple-system, "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121512; --card: #1b201c; --ink: #ecefe9; --muted: #9aa39b; --line: #2c332d; --brand: #a9c97a; --brand-ink: #10140f; --chip: #252b26; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { font-size: 16px; line-height: 1.45; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }

header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
header.top h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header.top .org { font-size: 12px; color: var(--muted); display: block; font-weight: 400; }
main { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }

nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; border: 0; background: none; padding: 9px 2px 8px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; min-height: 56px; }
nav.tabs button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }
nav.tabs button.on { color: var(--brand); font-weight: 700; }
nav.tabs .dot { position: absolute; top: 6px; left: 55%; background: var(--bad); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; line-height: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); letter-spacing: .2px; }
.sec { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 2px 8px; text-transform: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--brand); color: var(--brand-ink); font-weight: 700; min-height: 44px; cursor: pointer; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.bad { background: var(--bad); color: #fff; }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; min-height: 44px; font-size: 16px; }
textarea { min-height: 80px; resize: vertical; }
label.f { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.check input { width: 22px; height: 22px; }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--ink); white-space: nowrap; }
.chip.ok { background: #dcefd9; color: #1f5a2a; } .chip.warn { background: #fbecd0; color: #7a4a0c; } .chip.bad { background: #fadad7; color: #8a1c13; }
@media (prefers-color-scheme: dark) { .chip.ok { background: #1f3a24; color: #b8e3b0; } .chip.warn { background: #3d2e12; color: #f2cf8a; } .chip.bad { background: #431b17; color: #f4b1aa; } }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.filters button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-size: 14px; min-height: 36px; }
.filters button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.item { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .name { font-weight: 700; overflow-wrap: anywhere; }
.kids { margin: 6px 0 0 12px; padding-left: 10px; border-left: 2px solid var(--line); }
.kids .item { padding: 8px 0; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 18px; }
.stepper span { min-width: 26px; text-align: center; font-weight: 700; }

.cartbar { position: fixed; left: 12px; right: 12px; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 9; background: var(--brand); color: var(--brand-ink); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 736px; margin: 0 auto; }
.cartbar .grow { flex: 1; font-weight: 700; }
.cartbar button { background: var(--brand-ink); color: var(--brand); border: 0; border-radius: 10px; padding: 8px 14px; font-weight: 700; min-height: 40px; }

.post { border-left: 4px solid var(--line); }
.post.code_change, .post.rename { border-left-color: var(--accent); }
.post.missing, .post.lost, .post.broken { border-left-color: var(--bad); }
.post.low { border-left-color: var(--warn); }
.post .body { white-space: pre-wrap; margin-top: 6px; overflow-wrap: anywhere; }

dialog { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 760px; margin: auto auto 0; max-height: 92vh; background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .sheet { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
@media (min-width: 700px) { dialog { border-radius: 18px; margin: auto; } }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

.login { max-width: 380px; margin: 0 auto; padding: 14vh 20px 40px; }
.login h1 { font-size: 26px; margin: 0 0 4px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 20px; background: var(--chip); padding: 10px; border-radius: 10px; text-align: center; letter-spacing: 1px; user-select: all; }
.stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat .card { margin: 0; }
.stat b { font-size: 26px; display: block; }
.tl { text-align: left; } .tr { text-align: right; } .fw4 { font-weight: 400; } .mt6 { margin-top: 6px; } .sp8 { height: 8px; } .w80 { width: 80px !important; }
[hidden] { display: none !important; }
main.withcart { padding-bottom: 96px; }
.sheet:focus { outline: none; }

/* ---------- รอบสวย: หน้าแรก ---------- */
.hello { margin: 6px 2px 14px; }
.hello-name { font-size: 24px; font-weight: 800; letter-spacing: -.2px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qbtn { border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 2px; min-height: 104px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.qbtn svg { width: 26px; height: 26px; stroke: var(--brand); fill: none; stroke-width: 1.8; margin-bottom: 6px; }
.qbtn b { font-size: 16px; } .qbtn span { font-size: 13px; color: var(--muted); }
.qbtn.primary { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); border-color: var(--brand); min-height: 96px; }
.qbtn.primary svg { stroke: var(--brand-ink); } .qbtn.primary span { color: var(--brand-ink); opacity: .8; }
.qbtn:active, .tile:active, .irow .item:active { transform: scale(.99); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 12px 14px; text-align: left; display: flex; flex-direction: column; cursor: pointer; }
.num { font-variant-numeric: lining-nums tabular-nums; font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 700; line-height: 1.1; color: var(--brand); }

/* ---------- รอบสวย: ของ ---------- */
.stickybar { position: sticky; top: var(--hdr, 58px); z-index: 4; background: var(--bg); margin: -12px -16px 0; padding: 10px 16px 2px; border-bottom: 1px solid var(--line); }
.searchbox { position: relative; }
.searchbox input { padding-right: 44px; border-radius: 14px; font-size: 16px; min-height: 48px; }
.searchbox .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--chip); font-size: 20px; line-height: 1; cursor: pointer; }
.count { margin: 10px 2px 0; }
.card.list { padding: 2px 14px; }
.irow .item { cursor: pointer; padding: 12px 0; }
.irow.sel > .item .name { color: var(--brand); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 3px; }
.loc { font-size: 12px; color: var(--muted); }
.who { font-size: 12px; color: var(--warn); }
.pick { width: 44px; height: 44px; min-width: 44px; border-radius: 50%; border: 1.5px solid var(--brand); background: var(--card); color: var(--brand); font-size: 22px; font-weight: 700; cursor: pointer; line-height: 1; }
.pick.on { background: var(--brand); color: var(--brand-ink); }
.stepper button.pick { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--brand); }
.kvs { margin: 12px 0 4px; border-top: 1px solid var(--line); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
header.top { box-shadow: 0 1px 0 var(--line); }
.card { box-shadow: 0 1px 2px rgba(0,0,0,.03); }
input[type=search]::-webkit-search-cancel-button, input[type=search]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

/* ---------- ป้าย QR (พิมพ์) ---------- */
.labels { display: none; }
@media print {
  @page { size: A4; margin: 8mm; }
  html, body.printing { background: #fff !important; padding: 0; }
  body.printing > *:not(.labels) { display: none !important; }
  body.printing .labels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm; color: #000; }
  .label { border: 0.3mm dashed #999; border-radius: 2mm; padding: 2.5mm; text-align: center; break-inside: avoid; height: 45mm; overflow: hidden; }
  .label img { width: 26mm; height: 26mm; image-rendering: pixelated; }
  .lcode { font-family: ui-monospace, Menlo, monospace; font-size: 8.5pt; font-weight: 700; margin-top: 1mm; }
  .lname { font-size: 7.5pt; line-height: 1.25; max-height: 2.6em; overflow: hidden; }
}
