:root {
  --bg: #faf7f5; --card: #ffffff; --ink: #1f1a17; --muted: #756b66; --line: #e6dfda;
  --brand: #b3261e; --brand-ink: #ffffff; --ok: #1e7a3c; --warn: #b26a00; --bad: #b3261e;
  --bar-h: calc(52px + env(safe-area-inset-top)); --submit-h: 96px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161312; --card: #211d1b; --ink: #f3ece8; --muted: #a39892; --line: #373029; --brand: #e0564d; --ok: #5fc27f; --warn: #e3a34a; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, 'Noto Sans Thai', 'Sarabun', sans-serif; padding-bottom: env(safe-area-inset-bottom); }
header.bar { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink); height: var(--bar-h); padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; gap: 12px; }
header.bar h1 { font-size: 18px; margin: 0; flex: 1; }
header.bar button { background: transparent; border: 1px solid rgba(255,255,255,.6); color: inherit; border-radius: 8px; padding: 6px 10px; font: inherit; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 12px 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, select, button { font: inherit; }
input[type=text], input[type=password], input[type=date], select { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
button.primary { width: 100%; margin-top: 16px; padding: 14px; border: 0; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.tabs button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.status { position: sticky; top: var(--bar-h); z-index: 4; padding: 6px 16px; font-size: 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
.status.pending { color: var(--warn); }
.status.ok { color: var(--ok); }
.row { padding: 10px 14px; border-top: 1px solid var(--line); }
.row .name { font-weight: 600; }
[hidden] { display: none !important; }
.head { display: flex; align-items: center; gap: 10px; }
.head .name { flex: 1; min-width: 0; }
.viol-msg { margin-top: 8px; font-size: 13px; color: var(--bad); font-weight: 600; }
.gprev { font-size: 13px; margin-top: 6px; }
input.saving { border-color: var(--warn); }
input.saved { border-color: var(--ok); }
input.pending { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--card)); }
input.bad { border-color: var(--bad); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
tr.today td { font-weight: 600; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.warn { color: var(--warn); }
button.secondary { min-height: 44px; padding: 10px 14px; border: 1px solid var(--brand); border-radius: 10px; background: var(--card); color: var(--brand); font-weight: 600; }
.owner-tabs { margin-bottom: 8px; }
.branch-tabs { margin: 8px 0; }
.filterrow { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
button.toggle { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); white-space: nowrap; }
button.toggle.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.toggle:disabled { opacity: .5; }
.low-count { font-size: 13px; margin: 0; white-space: nowrap; }
.fresh { font-size: 13px; margin: 4px 0 8px; }
/* Stock cover: every item is exactly one line. No wrapping, no truncation, no ellipsis; a narrow screen scrolls sideways. */
.cover-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table.cover { width: auto; min-width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.cover th, table.cover td { padding: 4px 8px; white-space: nowrap; text-align: right; background: var(--card); }
table.cover th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.cover th:first-child, table.cover td:first-child { text-align: left; position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: 1px 0 0 var(--line); }
table.cover td.name { font-weight: 400; }
table.cover td.num.low { color: var(--bad); font-weight: 700; }
table.cover td.num.good { color: var(--ok); font-weight: 600; }
table.cover td.dim { color: var(--muted); }
table.cover input.qty { width: 64px; padding: 3px 6px; font-size: 13px; border-radius: 6px; text-align: right; font-variant-numeric: tabular-nums; }
table.cover .unit { font-size: 12px; display: inline-block; min-width: 2.5em; text-align: left; }
main:has(.cover-wrap) { max-width: 960px; }
table.cover.nostick th:first-child, table.cover.nostick td:first-child { position: static; box-shadow: none; }

.ci-result { font-size: 18px; font-weight: 600; }
.ci-ok { color: var(--ok); }
.ci-late, .ci-pending { color: var(--warn); }
.ci-bad { color: var(--bad); }
.ci-card input[type=password] { font-size: 22px; letter-spacing: 6px; text-align: center; }

main { padding: 12px 16px calc(var(--submit-h) + 16px); max-width: 720px; margin: 0 auto; }

/* ---- Count screen: Shelf List ---- */
:root { --submit-h: 76px; --top-h: 72px; }
.sl-head { display: flex; align-items: center; gap: 10px; max-width: 720px; margin: 0 auto; padding: calc(8px + env(safe-area-inset-top)) 16px 4px; }
.datepill { flex: 1; display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; }
.datepill input { width: auto; min-height: 40px; padding: 6px 12px; border-radius: 99px; font-size: 14px; }
.more { position: relative; }
.more summary { list-style: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; font-size: 22px; line-height: 1; background: var(--card); border: 1px solid var(--line); cursor: pointer; }
.more summary::-webkit-details-marker { display: none; }
.more .menu { position: absolute; right: 0; top: 50px; z-index: 20; min-width: 240px; padding: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.more .menu button { display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 10px; background: none; color: var(--ink); text-align: left; }
.more .menu button:active { background: var(--bg); }
.sl-top { position: sticky; top: 0; z-index: 5; padding: 6px 16px 0; background: var(--bg); }
.sl-top > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.sl-row { display: flex; align-items: baseline; justify-content: space-between; }
.sl-row h1 { margin: 0; font-size: 24px; letter-spacing: -.3px; }
.sl-row .cnt { font-size: 15px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.sl-top .bar { height: 5px; margin-top: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.sl-top .bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width .25s; }
.sl-top .status { position: static; padding: 4px 0 6px; border: 0; background: none; font-size: 12px; min-height: 26px; }
.sl-main { padding-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; border: 0; border-radius: 99px; background: var(--card); color: var(--ink); font-size: 13px; font-weight: 600; box-shadow: 0 0 0 1px var(--line) inset; }
.chip i { font-style: normal; font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.done i { color: var(--ok); }
section.cat h3 { position: sticky; top: var(--top-h); z-index: 3; display: flex; justify-content: space-between; margin: 0; padding: 14px 4px 6px; background: var(--bg); font-size: 12px; font-weight: 700; letter-spacing: .4px; color: var(--muted); }
section.cat h3 .prog { font-variant-numeric: tabular-nums; }
.grp { background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: 0 0 0 1px var(--line) inset; }
.grp .row { padding: 0; border-top: 1px solid var(--line); }
.grp .row:first-child { border-top: 0; }
.line { display: flex; align-items: center; gap: 12px; padding: 9px 12px; min-height: 62px; }
.members .line { min-height: 54px; padding-left: 28px; }
.members .ln + .ln, .members .ln:not(:first-child) { border-top: 1px dashed var(--line); }
button.nm { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 4px 0; border: 0; background: none; color: var(--ink); text-align: left; font: inherit; }
button.nm b { max-width: 100%; font-size: 15px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
button.nm .sub { max-width: 100%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line input.end { flex: none; width: 82px; height: 46px; padding: 0 6px; border-radius: 12px; border: 2px solid transparent; background: var(--bg); text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.line input.end::placeholder { color: var(--muted); opacity: .45; font-weight: 500; }
.line input.end:focus { outline: 0; background: var(--card); border-color: var(--brand); }
.line input.end.saved { border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.line input.end.saving { border-color: var(--warn); }
.line input.end.pending { border-color: var(--warn); }
.line input.end.bad { border-color: var(--bad); }
.ex { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 6px 12px 12px 66px; background: color-mix(in srgb, var(--brand) 4%, var(--card)); }
.members .ex { padding-left: 80px; }
.ex label { margin: 0; font-size: 12px; }
.ex input { height: 44px; padding: 0 6px; text-align: center; font-size: 17px; font-weight: 700; }
.ex .f-y, .ex .wide, .ex .gprev { grid-column: 1 / -1; }
.ex .f-y { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ex .f-y input { width: 96px; flex: none; }
.ex .f-y.ro { color: var(--muted); }
.ex .f-y.ro .val { font-weight: 600; color: var(--ink); }
.ex .f-y.ro .lbl { display: inline; margin: 0; }
.ex .gprev { margin: 0; }
.row.viol { background: color-mix(in srgb, var(--bad) 6%, var(--card)); box-shadow: 3px 0 0 var(--bad) inset; }
.row .viol-msg { margin: 0; padding: 0 12px 10px 66px; }
.tile { position: relative; flex: none; width: 44px; height: 44px; padding: 9px; border-radius: 13px; background: var(--tile-bg); color: var(--tile-ink); }
.tile.sm { width: 36px; height: 36px; padding: 7px; border-radius: 11px; }
.tile .ico { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tile.ok::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 17px; height: 17px; border-radius: 50%; border: 2px solid var(--card); background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.2 8.4l2.4 2.4 5-5.2' fill='none' stroke='%23fff' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.tone-meat { --tile-bg: #fbe4e0; --tile-ink: #b3261e; }
.tone-veg { --tile-bg: #e1f1dd; --tile-ink: #2b7428; }
.tone-pack { --tile-bg: #f3e8d2; --tile-ink: #8a5a12; }
.tone-drink { --tile-bg: #dde9f8; --tile-ink: #1f5fa8; }
.tone-sea { --tile-bg: #d8f0ee; --tile-ink: #17766f; }
.tone-misc { --tile-bg: #ebe2f5; --tile-ink: #6a3d9a; }
@media (prefers-color-scheme: dark) {
  .tone-meat { --tile-bg: #3d1f1c; --tile-ink: #ff958c; }
  .tone-veg { --tile-bg: #1d3320; --tile-ink: #8bd68a; }
  .tone-pack { --tile-bg: #3a2e18; --tile-ink: #e6b866; }
  .tone-drink { --tile-bg: #1a2c42; --tile-ink: #8fbdf0; }
  .tone-sea { --tile-bg: #153532; --tile-ink: #7fd3cb; }
  .tone-misc { --tile-bg: #2c2239; --tile-ink: #c8a2ef; }
}
.submitbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: center; gap: 12px; max-width: 720px; margin: 0 auto; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.submitbar .sub-msg { flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; color: var(--muted); }
.submitbar button.primary { flex: none; width: auto; max-width: 58%; min-height: 48px; margin: 0; padding: 0 22px; border-radius: 14px; font-size: 16px; }
.submitbar button.primary:disabled { background: var(--muted); opacity: .8; }

/* ---- Count screen: view toggle + Picture Grid skin (same DOM as the list; classes switch the layout) ---- */
.datepill input { width: 100%; }
.viewseg { display: flex; padding: 3px; border-radius: 12px; background: var(--line); }
.viewseg button { width: 40px; height: 38px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.viewseg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.ex-head, .ex-msg { display: none; }
.ex-msg { margin: 0; font-size: 13px; font-weight: 600; color: var(--bad); }

.grid-mode .grp { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; background: none; box-shadow: none; border-radius: 0; overflow: visible; }
.grid-mode .grp .row { border: 0; border-radius: 20px; background: var(--card); box-shadow: 0 0 0 1px var(--line) inset; }
.grid-mode .grp .row.gcard { grid-column: 1 / -1; border-radius: 16px; }
.grid-mode .row:not(.gcard) .line { flex-direction: column; align-items: stretch; gap: 6px; min-height: 0; padding: 12px 8px 8px; }
.grid-mode .row:not(.gcard) .tile { width: 54px; height: 54px; margin: 0 auto; padding: 12px; border-radius: 17px; }
.grid-mode .row:not(.gcard) button.nm { align-items: center; padding: 0; text-align: center; min-height: 32px; justify-content: center; }
.grid-mode .row:not(.gcard) button.nm b { font-size: 12.5px; line-height: 1.25; }
.grid-mode .row:not(.gcard) button.nm .sub { display: none; }
.grid-mode .row:not(.gcard) .line input.end { width: 100%; height: 42px; font-size: 19px; }
.grid-mode .row:not(.gcard):has(.tile.ok) { background: color-mix(in srgb, var(--ok) 9%, var(--card)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 40%, transparent) inset; }
.grid-mode .row:not(.gcard).viol, .grid-mode .row:not(.gcard).viol:has(.tile.ok) { background: color-mix(in srgb, var(--bad) 8%, var(--card)); box-shadow: 0 0 0 2px var(--bad) inset; }
.grid-mode .row:not(.gcard) .viol-msg { display: none; }
.grid-mode .row.viol .ex-msg { display: block; grid-column: 1 / -1; }
.grid-mode:has(.ln.open) { padding-bottom: 300px; }
.grid-mode:has(.ln.open)::before { content: ""; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.38); }
.grid-mode .ln { scroll-margin-top: calc(var(--top-h) + 36px); }
.grid-mode .ln.open > .ex { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; max-width: 720px; margin: 0 auto; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--card); border-radius: 24px 24px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.28); gap: 10px; }
.grid-mode .ln.open > .ex::before { content: ""; grid-column: 1 / -1; justify-self: center; width: 36px; height: 5px; border-radius: 3px; background: var(--line); }
.grid-mode .ex-head { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 12px; }
.grid-mode .ex-head b { font-size: 16px; }
.grid-mode .ex-head button { min-height: 42px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.grid-mode .ln.open > .ex input { height: 50px; font-size: 20px; }