:root {
  --green: #0f6b46;
  --green-dark: #0a4f33;
  --green-soft: #e4f3ec;
  --ink: #17211c;
  --muted: #66736c;
  --line: #dfe5e1;
  --bg: #f4f6f4;
  --card: #ffffff;
  --warn: #c2680a;
  --warn-soft: #fdf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 10px; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn.primary, .btn.pay { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:active, .btn.pay:active { background: var(--green-dark); }
.btn.big { min-height: 56px; font-size: 18px; width: 100%; }
.btn.small { min-height: 40px; padding: 0 14px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--green); font-weight: 600; padding: 12px 0; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: #fff; border-radius: 10px; display: grid; place-items: center; }

/* ---------- login ---------- */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--green); }
.card { background: var(--card); border-radius: 20px; padding: 24px; width: 100%; max-width: 380px; display: grid; gap: 14px; }
.card h1 { margin: 0; font-size: 26px; }
.card p { margin: 0; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
input {
  min-height: 50px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; font-size: 17px; width: 100%;
}
input:focus { outline: 3px solid var(--green-soft); border-color: var(--green); }

/* ---------- app layout ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; }
.top {
  background: var(--green); color: #fff; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
}
.who { display: grid; line-height: 1.2; min-width: 0; }
.who strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { opacity: .8; }
.top-r { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); }
.dot.ok { background: #5be39a; }
.dot.off { background: #ffb347; }
.badge { border: 0; border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: 13px; background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.scanbar { display: flex; gap: 8px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.cam-btn {
  min-width: 92px; border: 0; border-radius: 12px; background: var(--green); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px;
}

#cam { background: #000; }
#cam-view { position: relative; height: 34vh; min-height: 210px; max-height: 320px; overflow: hidden; display: grid; place-items: center; }
#cam-video { width: 100%; height: 100%; object-fit: cover; }
#cam-fallback { position: absolute; inset: 0; }
#cam-fallback video { width: 100% !important; height: 100% !important; object-fit: cover; }
.reticle {
  position: absolute; left: 12%; right: 12%; top: 30%; bottom: 30%; pointer-events: none;
  border: 3px solid rgba(91,227,154,.9); border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.38);
}
.cam-row .btn { background: transparent; color: #fff; border-color: #666; }
.cam-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; color: #fff; background: #111; }

#main { flex: 1; overflow-y: auto; padding: 10px 12px 14px; -webkit-overflow-scrolling: touch; }
.tiles { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.tiles::-webkit-scrollbar { display: none; }
.tile {
  flex: 0 0 auto; min-height: 56px; padding: 6px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); text-align: left; display: grid; align-content: center; line-height: 1.2;
}
.tile b { font-size: 15px; } .tile span { color: var(--muted); font-size: 13px; }

.empty { text-align: center; padding: 48px 16px; }
.cart { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.line {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
}
.line.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background: var(--green-soft); border-color: var(--green); } to { background: var(--card); } }
.line .nm { font-weight: 700; overflow-wrap: anywhere; }
.line .pr { color: var(--muted); font-size: 14px; }
.line .lt { font-weight: 800; font-size: 17px; text-align: right; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 22px; font-weight: 700; }
.stepper input { width: 64px; min-height: 44px; text-align: center; padding: 0 4px; font-weight: 700; }
.rm { justify-self: end; background: none; border: 0; color: var(--bad); font-weight: 600; font-size: 14px; padding: 8px 0 8px 8px; }

.bar {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px calc(10px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line);
}
.tot { display: grid; text-align: center; line-height: 1.15; }
.tot small { color: var(--muted); } .tot strong { font-size: 26px; }
.btn.pay { min-width: 112px; min-height: 56px; font-size: 19px; letter-spacing: .5px; }

/* ---------- bottom sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
#sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
#sheet-panel {
  position: relative; width: 100%; max-height: 92dvh; overflow-y: auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 8px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 21px; }
.sheet { display: grid; gap: 12px; }
.sheet .row { display: flex; gap: 8px; }
.sheet .row > * { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; }
.chip.on { background: var(--green-soft); border-color: var(--green); color: var(--green-dark); }
.big-num { font-size: 34px; font-weight: 800; text-align: center; }
.change { background: var(--green-soft); border-radius: 12px; padding: 10px; text-align: center; font-weight: 700; }
.change.short { background: var(--warn-soft); color: var(--warn); }
.list { display: grid; gap: 6px; }
.item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left;
  min-height: 52px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; width: 100%;
}
.item small { color: var(--muted); display: block; }
.receipt { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: #fafafa; border: 1px dashed var(--line); border-radius: 10px; padding: 12px; }
.receipt .r { display: flex; justify-content: space-between; gap: 8px; }
.receipt hr { border: 0; border-top: 1px dashed #bbb; margin: 8px 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); z-index: 80;
  max-width: 92vw; padding: 11px 16px; border-radius: 12px; background: #1d2a23; color: #fff; font-weight: 600; text-align: center;
}
#toast.err { background: var(--bad); } #toast.warn { background: var(--warn); } #toast.ok { background: var(--green); }

/* ---------- printing (58mm thermal friendly) ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; width: 58mm; font: 12px/1.3 ui-monospace, monospace; color: #000; }
  #print-area .r { display: flex; justify-content: space-between; }
  #print-area hr { border: 0; border-top: 1px dashed #000; }
}
.seg { display: inline-flex; background: #e6ebe8; border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { min-height: 40px; padding: 0 18px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--green-dark); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- reports page ---------- */
a.btn { display: grid; place-items: center; text-decoration: none; color: inherit; }
body.rep { background: var(--bg); }
.rep .top { gap: 10px; }
.rep .top strong { font-size: 18px; }
.back { color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; min-height: 44px; display: grid; place-items: center; padding: 0 10px 0 4px; }
.muted-w { color: rgba(255,255,255,.8); font-size: 14px; max-width: 34vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.tabs button { flex: 1; min-height: 50px; border: 0; background: none; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--green-dark); border-bottom-color: var(--green); }
.chips.range { padding: 10px 12px 0; }
.rep-main { padding: 6px 14px 40px; max-width: 720px; margin: 0 auto; }
.rep h3 { margin: 22px 0 8px; font-size: 16px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 2px; align-content: start; }
.kpi small { color: var(--muted); font-weight: 600; }
.kpi b { font-size: 21px; overflow-wrap: anywhere; }
.kpi span { color: var(--muted); font-size: 12px; line-height: 1.25; }
.kpi.good { background: var(--green-soft); border-color: #b9dccb; }
.kpi.good b { color: var(--green-dark); }
.kpi.bad { background: var(--bad-soft); border-color: #f1c4bf; } .kpi.bad b { color: var(--bad); }
.kpi.wide { grid-column: 1 / -1; }
.note { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: #eef1ef; font-size: 14px; }
.note.warn { background: var(--warn-soft); color: #7a4306; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px 6px; }
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.dbar { width: 100%; max-width: 34px; background: var(--green); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar-col small { font-size: 10px; color: var(--muted); white-space: nowrap; }
.hrow { position: relative; display: flex; justify-content: space-between; padding: 12px; margin-bottom: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.hrow span, .hrow b { position: relative; z-index: 1; }
.hrow i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green-soft); }
.row2 { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 12px; margin-bottom: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.row2 > span { min-width: 0; overflow-wrap: anywhere; }
.row2 small, .mini { display: block; color: var(--muted); font-size: 13px; }
.row2 em { font-style: normal; display: inline-block; min-width: 20px; color: var(--muted); font-weight: 700; }
.row2 b { white-space: nowrap; }
.shift { margin-bottom: 8px; }
.shift .row2 { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.mini { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 12px; background: #fafbfa; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px; }
.ok { color: var(--green); } .neg { color: var(--bad); } .pos { color: var(--warn); }
.rep .chips { margin: 4px 0 10px; }
.rep .error { margin-top: 12px; }

.chips.range { flex-wrap: nowrap; gap: 6px; }
.chips.range .chip { flex: 1; min-width: 0; padding: 0 4px; font-size: 15px; }

/* ---------- menu / staff sheets ---------- */
.sheet .row .btn { padding: 0 8px; }
.sheet .item[disabled] { opacity: .5; }

/* ---------- items screen ---------- */
select { min-height: 50px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-size: 17px; width: 100%; }
select:focus { outline: 3px solid var(--green-soft); border-color: var(--green); }
.lbl { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.filters { padding: 8px 12px 0; overflow-x: auto; flex-wrap: nowrap; }
.filters .chip { flex: none; min-height: 40px; }
body.items .rep-main { padding-bottom: 96px; }
.tags { display: flex; gap: 4px; flex: none; }
.tag { font-style: normal; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: #e8ece9; color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: #7a4306; }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.fab { position: fixed; left: 14px; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 6; min-height: 56px; border-radius: 16px; border: 0; background: var(--green); color: #fff; font-size: 18px; font-weight: 800; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 692px; margin: 0 auto; }
.fab:active { background: var(--green-dark); }
label.check { display: flex; align-items: center; gap: 12px; font-weight: 600; }
label.check input { width: 26px; min-height: 26px; height: 26px; flex: none; }
.bc-add { display: flex; gap: 8px; margin-top: 8px; } .bc-add input { flex: 1; } .bc-add .btn { flex: none; }
body.items #cam { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; }
body.items #cam[hidden] { display: none; }
body.items #cam-view { flex: 1; height: auto; max-height: none; }
.item b { white-space: nowrap; }
.row2 .btn, .item .btn { flex: none; white-space: nowrap; }

/* tabs scroll sideways when there are many */
.tabs { overflow-x: auto; scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 0 14px; }

.badge.ask { background: var(--warn-soft); color: #7a4306; border-color: #e8c98a; }
