:root {
  --green: #2f6b3a;
  --green-soft: #e6f0e7;
  --ink: #1f2420;
  --muted: #6b716c;
  --line: #dcdcd4;
  --bg: #f6f5f0;
  --card: #ffffff;
  --red: #b3261e;
  --red-soft: #fbe9e7;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--green); }
h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: .85rem; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.between { justify-content: space-between; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--green); color: #fff;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar .me { font-size: .85rem; opacity: .9; }

.app { max-width: 960px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 6px 0 8px; font-size: .75rem; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.3rem; line-height: 1.4; }
.tabbar a.active { color: var(--green); font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
button.primary, .btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.danger { color: var(--red); border-color: #e7b9b5; }
button.big { width: 100%; font-size: 1.1rem; min-height: 54px; }
button:disabled { opacity: .5; cursor: default; }
button.chip { min-height: 36px; padding: 6px 12px; border-radius: 999px; font-size: .9rem; }
button.chip.on, button.seg.on { background: var(--green); color: #fff; border-color: var(--green); }

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink); min-height: 44px;
}
textarea { min-height: 70px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: .95rem; }
.check input { width: auto; min-height: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list a, .list .item {
  display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.list > :last-child { border-bottom: 0; }
.list .sub { font-size: .8rem; color: var(--muted); }
.void { text-decoration: line-through; color: var(--muted); }
.badge { font-size: .7rem; padding: 2px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-weight: 600; }
.badge.red { background: var(--red-soft); color: var(--red); }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.pos > div { min-width: 0; }
@media (max-width: 799px) { .pos { padding-bottom: 72px; } }
@media (min-width: 800px) { .pos { grid-template-columns: minmax(0, 1fr) 340px; } .cartbar { display: none !important; } }
.cartbar {
  position: fixed; left: 8px; right: 8px; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--green); color: #fff; border-radius: 12px; padding: 10px 14px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.cartbar button { background: #fff; color: var(--green); border: 0; font-weight: 700; min-height: 38px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; }
.chips button { flex: 0 0 auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
.tile {
  flex-direction: column; align-items: flex-start; justify-content: space-between;
  min-height: 86px; padding: 10px; text-align: left; background: #fff;
}
.tile .n { font-weight: 600; font-size: .95rem; line-height: 1.2; }
.tile .u { font-size: .78rem; color: var(--muted); }
.tile .p { font-weight: 700; color: var(--green); }
.cart { position: sticky; top: 60px; align-self: start; }
.cart-line { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cart-line .d { flex: 1; font-size: .92rem; }
.cart-line .q { display: flex; align-items: center; gap: 4px; }
.cart-line .q button { min-height: 34px; width: 34px; padding: 0; }
.total { display: flex; justify-content: space-between; font-size: 1.25rem; font-weight: 700; margin: 12px 0; }
.segs { display: flex; gap: 6px; margin-bottom: 10px; }
.segs button { flex: 1; }

/* Modal and toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 600px) { .modal { align-items: center; } }
.modal .sheet { background: #fff; width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 18px; max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { .modal .sheet { border-radius: 16px; } }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions button { flex: 1; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; }
.toast.err { background: var(--red); }

/* Documents: POS receipt (58 mm) and cash bill (A4) */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.receipt { max-width: 300px; margin: 0 auto 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.receipt .c { text-align: center; }
.receipt table, .bill table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 2px 0; vertical-align: top; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 6px 0; }
.bill { max-width: 800px; margin: 0 auto 12px; }
.bill .lh { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; border-bottom: 2px solid var(--green); padding-bottom: 10px; margin-bottom: 14px; }
.bill .lh > div:first-child { flex: 1 1 260px; }
.bill .lh .name { font-size: 1.35rem; font-weight: 800; color: var(--green); }
.bill .meta { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.bill th, .bill td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.bill th.r, .bill td.r { text-align: right; }
.bill .tot td { border: 0; font-weight: 700; }
.stamp { display: inline-block; border: 2px solid var(--green); color: var(--green); font-weight: 800; padding: 2px 10px; border-radius: 6px; transform: rotate(-4deg); }
.stamp.red { border-color: var(--red); color: var(--red); }
.photo { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }

@media print {
  body { background: #fff; padding: 0; }
  .no-print, .topbar, .tabbar, .modal, .toast { display: none !important; }
  .app { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; margin: 0; }
  body.print-receipt .receipt { max-width: 58mm; margin: 0; font-size: 11px; }
}
