:root {
  --bg: #f6f1ea; --ink: #2b1d14; --brown: #3b2a20; --accent: #c8832f; --accent-d: #a96a1f;
  --ok: #1f7a3d; --wait: #b25e00; --bad: #b3261e; --cancel: #6b6b6b; --line: #ddd2c4; --card: #fff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body { margin: 0; min-height: 100%; } /* min-height (không phải height) để khoảng đệm dưới của body có tác dụng, nội dung cuối không bị thanh dưới che */
body {
  background: var(--bg); color: var(--ink); font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-top: calc(56px + env(safe-area-inset-top, 0px)); padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  overscroll-behavior: contain; user-select: none; -webkit-user-select: none;
}
body.has-cart main { padding-bottom: 170px; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; user-select: text; -webkit-user-select: text; }
.hidden { display: none !important; }

/* thanh trên */
#hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: env(safe-area-inset-top, 0px) 12px 0; height: calc(56px + env(safe-area-inset-top, 0px)); background: var(--brown); color: #fff;
}
#hdr .title { font-weight: 700; font-size: 20px; margin-right: auto; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.pill.online { background: #cfe9d6; color: #14532d; }
.pill.offline { background: #ffd9d6; color: #7a1410; }
.pill.wait { background: #ffe3b3; color: #6d3b00; border: 0; }
.pill.bad { background: #ffd9d6; color: #7a1410; border: 0; }

/* thông báo */
.banner { margin: 8px 12px 0; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
.banner.warn { background: #ffe9c2; color: #5c3600; }
.banner.bad { background: #ffd9d6; color: #6e1410; }
.banner.info { background: #e3ecf7; color: #1d3557; }

main { padding: 8px 12px 24px; }

/* chọn danh mục */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-height: 44px; padding: 0 16px; border-radius: 999px; background: #e9dfd2; font-weight: 600; }
.chip.on { background: var(--brown); color: #fff; }

/* lưới món */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.cname { font-weight: 700; font-size: 17px; min-height: 44px; }
.sizes { display: flex; gap: 8px; }
.size { flex: 1; min-height: 56px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; }
.size:active { background: var(--accent-d); transform: scale(.97); }
.size b { font-size: 19px; margin-right: 4px; }
.note { color: #7a6a5c; font-size: 14px; text-align: center; margin: 14px 0; }
.empty { text-align: center; color: #7a6a5c; padding: 40px 16px; }

/* thanh giỏ hàng */
#bar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); z-index: 15;
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.12); padding: 8px 12px 10px;
}
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button { flex: 1; min-height: 44px; border-radius: 10px; background: #efe7dc; font-weight: 600; font-size: 15px; }
.seg button.on { background: var(--brown); color: #fff; }
.barrow { display: flex; gap: 8px; }
.cartbtn { flex: 0 0 38%; min-height: 60px; border-radius: 12px; background: #efe7dc; font-weight: 600; text-align: left; padding: 0 12px; line-height: 1.2; }
.cartbtn small { display: block; color: #6b5b4d; font-weight: 500; }
.save { flex: 1; min-height: 60px; border-radius: 12px; background: var(--ok); color: #fff; font-weight: 800; font-size: 18px; }
.save:disabled { opacity: .55; }
.save:active { filter: brightness(.9); }

/* thanh dưới */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#nav button { flex: 1; height: 64px; background: transparent; font-size: 14px; font-weight: 600; color: #6b5b4d; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#nav button span { font-size: 22px; line-height: 1; }
#nav button.on { color: var(--brown); box-shadow: inset 0 3px 0 var(--accent); }

/* lịch sử */
.row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; width: 100%; text-align: left; min-height: 64px; }
.row .no { font-weight: 800; min-width: 44px; }
.row .mid { flex: 1; min-width: 0; }
.row .amt { font-weight: 700; }
.row small { color: #6b5b4d; display: block; }
.st { display: inline-block; border-radius: 8px; padding: 2px 8px; font-size: 13px; font-weight: 700; margin-top: 3px; }
.st.ok { background: #d5efdc; color: var(--ok); }
.st.wait { background: #ffe3b3; color: var(--wait); }
.st.bad { background: #ffd9d6; color: var(--bad); }
.st.cancel { background: #e5e5e5; color: var(--cancel); }
.sum { background: var(--brown); color: #fff; border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
.sum small { opacity: .8; }

/* hộp thoại */
#modal:empty { display: none; }
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet { background: #fff; width: 100%; max-height: 88vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px)); }
.sheet h2 { margin: 0 0 8px; font-size: 20px; }
.line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eee; }
.line .nm { flex: 1; min-width: 0; }
.line .nm small { display: block; color: #6b5b4d; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 48px; height: 48px; border-radius: 12px; background: #efe7dc; font-size: 24px; font-weight: 700; }
.qty b { min-width: 28px; text-align: center; font-size: 19px; }
.x { width: 44px; height: 48px; background: transparent; font-size: 20px; color: var(--bad); }
.total { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; padding: 12px 0 6px; }
.btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn { flex: 1; min-height: 56px; border-radius: 12px; font-weight: 700; padding: 0 14px; background: #e9dfd2; }
.btn.primary { background: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.dark { background: var(--brown); color: #fff; }
.reasons { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.reasons button { min-height: 48px; padding: 0 14px; border-radius: 12px; background: #efe7dc; font-weight: 600; }
.reasons button.on { background: var(--brown); color: #fff; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; margin: 8px 0; }
.kv span:nth-child(odd) { color: #6b5b4d; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; user-select: text; }

/* cài đặt, báo cáo */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 18px; }
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 15px; }
input, select { width: 100%; min-height: 52px; border: 1px solid #c9bcab; border-radius: 10px; padding: 0 12px; background: #fff; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.stat { background: #f3ece2; border-radius: 12px; padding: 10px; }
.stat small { color: #6b5b4d; display: block; }
.stat b { font-size: 20px; }
.stat.big { grid-column: 1 / -1; background: var(--brown); color: #fff; }
.stat.big small { color: #e8d9c7; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  max-width: 90vw; background: #222; color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: .96; }
#toast.err { background: var(--bad); }

/* món ngoài menu, sửa giá */
.custom { width: 100%; margin: 2px 0 10px; }
.hint { color: #6b5b4d; font-size: 14px; margin: 4px 0; }
.line .nm small.warn { color: var(--wait); font-weight: 700; }
.mini { margin-top: 4px; min-height: 40px; padding: 0 14px; border-radius: 10px; background: #efe7dc; font-weight: 600; font-size: 14px; }

/* ===== Ghi nợ, Thu – Chi, báo cáo tài chính ===== */
:root { --debt: #b25e00; --in: #1f7a3d; --out: #b3261e; }
#nav button { font-size: 12.5px; padding: 0 2px; }
#nav button span { font-size: 21px; }
.seg button { font-size: 14px; padding: 0 3px; line-height: 1.15; }
.seg button.debt { background: var(--debt); color: #fff; }
.save.debt { background: var(--debt); }
.btn.debtbtn { background: var(--debt); color: #fff; }
.btn.big { min-height: 64px; font-size: 17px; }
.btns.sticky { position: sticky; bottom: -14px; background: #fff; padding: 10px 0 4px; margin-top: 8px; }

.row.static { cursor: default; }
.row.cancelled .mid > div, .row.cancelled .amt { text-decoration: line-through; opacity: .6; }
.tx-row .no { min-width: 36px; text-align: center; font-size: 26px; line-height: 1; }
.no.in, .amt.in { color: var(--in); }
.no.out, .amt.out { color: var(--out); }
.row .amt { white-space: nowrap; }
input[type="search"], input[type="date"], input[type="datetime-local"] { width: 100%; }
#txSearch { margin: 4px 0 8px; }
#txGroup { margin-bottom: 8px; }
.seg.rep { margin-bottom: 10px; }
.seg.rep button { min-height: 48px; font-size: 16px; }

.panel.inner { background: #f8f3ec; margin-top: 12px; }
.panel.inner b { font-size: 20px; }
h4 { margin: 16px 0 6px; font-size: 17px; }
.kv.wide { grid-template-columns: 1fr auto; font-size: 16px; }
.kv.wide span:nth-child(even), .kv.wide b:nth-child(even) { text-align: right; font-weight: 700; color: var(--ink); }
.kv.wide span:nth-child(odd) { color: #4b3b2e; }

.chart { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.chart svg { display: block; }
.legend { font-size: 14px; color: #4b3b2e; padding: 2px 4px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.dot.in { background: #1f7a3d; } .dot.out { background: #b3261e; }

.gbar { margin: 8px 0 12px; }
.gline { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; margin-bottom: 4px; }
.gtrack { height: 12px; background: #e9dfd2; border-radius: 8px; overflow: hidden; }
.gfill { height: 100%; background: var(--accent); border-radius: 8px; }

/* kho và hao hụt */
.stk { background: #f8f3ec; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.stk[data-status="CAN_XEM"] { border-color: var(--bad); background: #fff3f1; }
.stkhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.stag { display: inline-block; flex: 0 0 auto; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; text-align: right; }
.stag.bad { background: #ffd9d6; color: #6e1410; }
.stag.ok { background: #d9efdc; color: #1b5a2c; }
.stag.warn { background: #ffe9c2; color: #5c3600; }
.stag.gray { background: #e8e0d6; color: #4b3b2e; }
/* thẻ kho: nhãn trên, số dưới (màn hình điện thoại hẹp) */
.stk .kv.wide { grid-template-columns: 1fr; gap: 0; margin: 4px 0 0; }
.stk .kv.wide span:nth-child(odd) { font-size: 14px; margin-top: 8px; }
.stk .kv.wide span:nth-child(even) { text-align: left; font-size: 17px; }
.stkhead b { font-size: 17px; }
