:root {
  --bg: #f3f5f4; --card: #fff; --ink: #1b2422; --muted: #66736f; --line: #dfe5e3;
  --brand: #0f5c4d; --brand-2: #e7f2ef; --ok: #1d7f45; --warn: #a15c00; --bad: #b3261e; --vat: #1f4fa3;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--brand); color: #fff; padding-top: max(10px, env(safe-area-inset-top)); }
.bar button { background: rgba(255,255,255,.14); border: 0; color: #fff; width: 44px; height: 44px; border-radius: 12px; font-size: 22px; position: relative; }
.bar-title { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.bar-title strong { font-size: 17px; }
.dot { font-size: 12px; opacity: .9; }
.dot::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: #ffb4ab; vertical-align: 1px; }
.dot.on::before { background: #7ee2a8; }
.badge { position: absolute; top: -4px; right: -4px; background: #ffb020; color: #222; font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px; line-height: 20px; }

main { max-width: 720px; margin: 0 auto; padding: 14px 14px 120px; }
h2 { font-size: 20px; margin: 4px 0 12px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { border: 0; border-radius: var(--radius); background: var(--card); padding: 20px 12px; text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,.06); min-height: 112px; }
.tile .ic { font-size: 34px; display: block; }
.tile b { display: block; font-size: 17px; margin-top: 6px; }
.tile.main { grid-column: span 2; background: var(--brand); color: #fff; min-height: 120px; }
.tile.main .ic { font-size: 40px; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--brand-2); color: var(--brand); font-weight: 600; min-height: 48px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.block { width: 100%; }
.btn.danger { background: #fde7e5; color: var(--bad); }
.btn:disabled { opacity: .45; }

label.f { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input.in, select.in { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; min-height: 48px; }
input.in:focus, select.in:focus { outline: 2px solid var(--brand); border-color: transparent; }

/* two-choice switch: Cash/Credit, With VAT/Without VAT */
.seg { display: flex; background: #e9eeec; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; border-radius: 9px; padding: 11px 8px; background: transparent; font-weight: 600; color: var(--muted); min-height: 46px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.vat button.on { color: var(--vat); }

.pick { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; min-height: 56px; }
.pick .grow b { display: block; }
.list { border-radius: 12px; background: #fff; border: 1px solid var(--line); max-height: 46vh; overflow: auto; }
.list button { display: flex; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 12px; gap: 10px; align-items: center; min-height: 56px; }
.list button:last-child { border-bottom: 0; }
.list .r { margin-left: auto; text-align: right; white-space: nowrap; }
.stock0 { color: var(--bad); }

.line { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line .name b { display: block; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--brand-2); color: var(--brand); font-size: 22px; font-weight: 700; }
.qty input { width: 70px; text-align: center; border: 1px solid var(--line); border-radius: 10px; height: 44px; }
.rate { width: 96px; text-align: right; border: 1px solid var(--line); border-radius: 10px; height: 44px; padding: 0 8px; }
.amt { text-align: right; font-weight: 700; align-self: center; }
.x { background: none; border: 0; color: var(--bad); font-size: 14px; padding: 6px 0; }

.totals { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 10px 14px max(10px, env(safe-area-inset-bottom)); z-index: 4; }
.totals .in-w { max-width: 720px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.totals .sum { flex: 1; font-size: 14px; color: var(--muted); }
.totals .sum b { display: block; font-size: 24px; color: var(--ink); }

.chip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; }
.chip.local { background: #fff3d6; color: var(--warn); }
.chip.queued { background: #e3ecff; color: var(--vat); }
.chip.posted { background: #dff3e6; color: var(--ok); }
.chip.failed { background: #fde7e5; color: var(--bad); }
.chip.vat { background: #e3ecff; color: var(--vat); }
.err { color: var(--bad); font-size: 14px; margin-top: 4px; }

/* item cards: 2 per row on a phone, as many as fit on a tablet */
.items-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.items-grid button { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px; text-align: left;
  min-height: 92px; display: flex; flex-direction: column; gap: 2px; }
.items-grid button:active { background: var(--brand-2); }
.items-grid button.empty { opacity: .5; }
.items-grid b { font-size: 15px; line-height: 1.2; }
.items-grid .ip { margin-top: auto; display: flex; justify-content: space-between; gap: 6px; font-size: 14px; }

/* Tablets and big phones in landscape: items left, bill right, Save always in view */
@media (min-width: 900px) {
  html, body { font-size: 17px; }
  main { max-width: 1400px; padding: 16px 20px 24px; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile.main { grid-column: span 1; grid-row: span 2; }
  .doc { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr); gap: 16px; align-items: start; }
  .pane-right { position: sticky; top: 80px; }
  .pane-right .card { max-height: calc(100vh - 220px); overflow: auto; }
  .items-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); max-height: calc(100vh - 380px); overflow: auto; padding-bottom: 4px; }
  .pane-right .totals { position: static; border: 0; border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
  .pane-right .totals .sum b { font-size: 28px; }
  .pane-right .totals .btn { min-height: 60px; padding: 0 28px; font-size: 18px; }
}

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #222; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 20; max-width: 90vw; }

/* receipt: shown on screen inside a card, printed alone on an 80 mm roll */
.paper { background: #fff; max-width: 340px; margin: 0 auto; padding: 14px; font: 13px/1.35 "Courier New", monospace; color: #000; border: 1px dashed #bbb; }
.paper h3 { text-align: center; margin: 4px 0; font-size: 15px; }
.paper .c { text-align: center; }
.paper table { width: 100%; border-collapse: collapse; }
.paper td { padding: 2px 0; vertical-align: top; }
.paper td.n { text-align: right; white-space: nowrap; }
.paper hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.paper .big { font-size: 16px; font-weight: 700; }
.receipt-print { display: none; }
@media print {
  @page { size: 80mm auto; margin: 2mm; }
  body > *:not(.receipt-print) { display: none !important; }
  .receipt-print { display: block; }
  .receipt-print .paper { border: 0; max-width: none; padding: 0; }
}
