:root {
  --red: #7a1416;
  --red-2: #a3201f;
  --cream: #f7efe3;
  --card: #fffaf2;
  --ink: #2a1a14;
  --muted: #7b6a5f;
  --line: #e7d9c6;
  --yellow: #f5c518;
  --green: #1f7a3a;
  --radius: 14px;
  --bar-h: 76px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 12px);
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 10px;
  padding: 8px 14px 10px; background: var(--red); color: var(--cream);
}
.topbar .tabs { grid-column: 1 / -1; }
.topbar .tab { flex: 1; }
.brand { font-weight: 900; font-size: 22px; letter-spacing: -0.5px; font-style: italic; }
.event { font-size: 13px; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; background: rgba(0,0,0,.2); border-radius: 999px; padding: 3px; }
.tab { padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--cream); }
.tab.active { background: var(--cream); color: var(--red); }

main { padding: 12px 14px; max-width: 900px; margin: 0 auto; }

/* Category chips */
.cats { display: flex; gap: 8px; position: sticky; top: 96px; z-index: 4; background: var(--cream); padding: 8px 0; margin: -4px 0 4px; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.chip.active { background: var(--ink); color: var(--cream); border-color: var(--ink); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 2px 8px; font-weight: 700; }

/* Menu grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.item {
  position: relative; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; min-height: 96px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  transition: transform .08s ease;
}
.item:active { transform: scale(.97); background: #fff3df; }
.item-name { font-weight: 700; font-size: 16px; line-height: 1.2; padding-right: 22px; }
.item-desc { font-size: 12px; color: var(--muted); line-height: 1.3; }
.item-price { font-weight: 800; color: var(--red-2); font-size: 16px; }
.item-qty {
  position: absolute; top: 8px; right: 8px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}

/* Bottom order bar */
.orderbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0,0,0,.06);
}
.orderbar-view { border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-weight: 600; text-align: left; }
.orderbar-charge { background: var(--red); color: #fff; border-radius: 12px; padding: 14px; font-weight: 800; font-size: 18px; }
.orderbar-charge:disabled { opacity: .4; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20,10,5,.45); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: 90vh; overflow: auto; background: var(--cream);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 12px; font-size: 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.close { font-size: 26px; line-height: 1; padding: 4px 8px; color: var(--muted); }

/* Order lines */
.line { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; width: 100%; text-align: left; }
.line-qty { font-weight: 800; color: var(--red); min-width: 28px; }
.line-name { font-weight: 600; }
.line-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.line-total { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.total-row { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; padding: 12px 4px; }

/* Buttons */
.btn { display: block; width: 100%; padding: 15px; border-radius: 12px; font-weight: 700; font-size: 17px; text-align: center; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:disabled { opacity: .4; }
.btn-ghost { border: 1px solid var(--line); background: var(--card); }
.btn-danger { color: var(--red-2); border: 1px solid #e9b9b4; background: #fff4f2; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

/* Editor */
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 8px 0 16px; }
.stepper button { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 26px; font-weight: 700; }
.stepper span { font-size: 28px; font-weight: 800; min-width: 40px; text-align: center; }
.opt-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 8px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; font-weight: 600; font-size: 14px; }
.opt small { display: block; font-weight: 500; color: var(--muted); }
.opt.on { border-color: var(--red); background: #fde9e4; box-shadow: inset 0 0 0 1px var(--red); }

/* Checkout */
.big-total { text-align: center; font-size: 40px; font-weight: 900; color: var(--red); margin: 4px 0 14px; }
.pay-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pay-opts .opt { text-align: center; padding: 16px 8px; }
.cash-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.cash-quick button { padding: 12px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 700; }
.cash-input { width: 100%; padding: 14px; font-size: 22px; font-weight: 700; border-radius: 12px; border: 1px solid var(--line); background: #fff; margin-top: 8px; }
.change { text-align: center; font-size: 20px; margin: 14px 0 4px; }
.change b { color: var(--green); font-size: 28px; }

/* Receipt */
.receipt { background: #fff; border-radius: 12px; padding: 16px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14px; border: 1px dashed var(--line); }
.receipt .center { text-align: center; }
.receipt .row { display: flex; justify-content: space-between; gap: 10px; }
.receipt .sub { color: var(--muted); font-size: 12px; padding-left: 12px; }
.receipt hr { border: 0; border-top: 1px dashed #bbb; margin: 8px 0; }
.void-stamp { color: var(--red-2); font-weight: 900; text-align: center; font-size: 22px; letter-spacing: .2em; }

/* Sales view */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.stat.wide { grid-column: span 2; }
.pay-split { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.pay-split div { font-size: 13px; }
.pay-split b { display: block; font-size: 16px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.table td { padding: 9px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.table tr:first-child td { border-top: 0; }
.table td:last-child { text-align: right; font-weight: 700; }
.order-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.order-no { font-weight: 800; color: var(--red); }
.order-meta { font-size: 12px; color: var(--muted); }
.order-row.cancelled { opacity: .5; }
.order-row.cancelled > span:nth-child(2) > div:first-child, .order-row.cancelled > b { text-decoration: line-through; }
.tag { color: var(--red-2); font-weight: 700; }

/* Misc helpers */
.muted { color: var(--muted); font-weight: 600; font-size: 16px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.section-title .hint { margin-left: 6px; }
.stat-value.small { font-size: 20px; }
.mini-btn { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 700; font-size: 13px; }
#main > .order-row:has(.mini-btn) { grid-template-columns: 1fr auto auto; }
.btn-danger-solid { background: var(--red-2); color: #fff; }

/* Selectable options show a tick */
.opt { position: relative; padding-left: 38px; }
.pay-opts .opt { padding-left: 8px; }
.opt .tick { position: absolute; left: 12px; top: 13px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); background: #fff; }
.opt.on .tick { border-color: var(--red); background: var(--red); box-shadow: inset 0 0 0 3px #fff; }

/* Refund */
.refund-line { grid-template-columns: 1fr auto; cursor: default; }
.mini-stepper { display: flex; align-items: center; gap: 10px; }
.mini-stepper button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 20px; font-weight: 700; }
.mini-stepper b { min-width: 18px; text-align: center; font-size: 18px; }

/* Profit */
.event-pick { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font: inherit; font-weight: 600; margin-bottom: 12px; }
.notice { display: block; width: 100%; text-align: left; background: #fff6d6; border: 1px solid #f0d77a; color: #6b5200; border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 12px; }
.pl { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
.pl-row { display: flex; justify-content: space-between; align-items: baseline; padding: 11px 0; border-top: 1px solid var(--line); font-size: 16px; }
.pl-row:first-child { border-top: 0; }
.pl-row small { color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 12px; }
.pl-row.minus b { color: var(--muted); }
.pl-row.sub-total { font-weight: 700; }
.pl-row.grand { font-size: 20px; font-weight: 800; border-top: 2px solid var(--ink); }
.pl-row.grand b { color: var(--green); }
.pl-row.grand.loss b { color: var(--red-2); }
.exp-cat { font-weight: 700; }
#main > .order-row:has(.exp-cat) { grid-template-columns: auto 1fr auto; }
.table-wrap { overflow-x: auto; margin-bottom: 10px; }
.pl-table td { text-align: right; white-space: nowrap; padding: 9px 8px; }
.pl-table td:first-child { text-align: left; white-space: normal; font-weight: 600; }
.pl-table td:last-child { font-weight: 700; }
.pl-table tr.th td { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; background: #f3e8d6; }
.pl-table tr.tap { cursor: pointer; }
.pl-table tr.tap:active { background: #fff3df; }

/* Costs */
.group-label { font-weight: 800; margin: 14px 2px 6px; }
#main > .cost-row { grid-template-columns: 1fr auto; }
.cost-row b { text-align: right; font-size: 18px; color: var(--green); }
.cost-row b small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.cost-row .muted-b { color: var(--muted); }
.ing-row { grid-template-columns: 1fr auto; }
.ing-row b { color: var(--ink); }
.ing-row.unset b { color: var(--red-2); }
.recipe-row { display: grid; grid-template-columns: 1fr 64px 44px 64px 30px; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.recipe-row input { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--line); text-align: right; }
.recipe-row .unit { color: var(--muted); font-size: 12px; }
.recipe-row .rc { text-align: right; font-weight: 600; }
.recipe-row .close { font-size: 20px; padding: 0; }

/* Confirm */
.confirm-body { color: var(--ink); line-height: 1.45; margin-bottom: 6px; }
.row-sum { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.warn { color: var(--red-2); font-weight: 600; }

/* Event setup */
.setup { max-width: 460px; margin: 30px auto; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.setup h1 { margin: 0 0 4px; font-size: 24px; }
.setup p { color: var(--muted); margin: 0 0 16px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input { width: 100%; padding: 13px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar-h) + 20px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--cream); padding: 10px 14px; border-radius: 999px; z-index: 8;
  display: flex; gap: 12px; align-items: center; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
  white-space: nowrap; max-width: calc(100vw - 28px);
}
.toast span { overflow: hidden; text-overflow: ellipsis; }
.toast button { color: var(--yellow); font-weight: 700; }

/* Dashboard */
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red-2); }
.back { font-weight: 700; color: var(--red); padding: 6px 0; margin-bottom: 4px; }
.ev-title { margin: 4px 2px 8px; font-size: 22px; }
#main > .ev-row { grid-template-columns: 1fr auto; }
.ev-row b { text-align: right; }
.ev-row b small { display: block; font-size: 12px; color: var(--green); font-weight: 600; }
.pl.cash { margin-top: 10px; background: #fbf6ec; }
.pl-head { font-weight: 800; padding: 10px 0 2px; }
.pl-head small { color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 12px; }
.pl.cash .hint { margin: 4px 0 12px; }
#main > .exp-row { grid-template-columns: 1fr auto; }

/* Should I join? */
.join-card { display: block; width: 100%; text-align: left; margin: 14px 0 0; padding: 14px 16px; border-radius: var(--radius); background: var(--ink); color: var(--cream); }
.join-card b { display: block; font-size: 17px; }
.join-card span { font-size: 13px; opacity: .8; }
.opts-3 { grid-template-columns: repeat(3, 1fr); }
.opts-3 .opt { padding-left: 8px; text-align: center; }
.join-result { border-radius: var(--radius); padding: 14px; margin: 6px 0 8px; border: 2px solid var(--line); background: var(--card); }
.join-result.muted-box { color: var(--muted); border-style: dashed; text-align: center; }
.join-result.z-join { border-color: #2e8b57; background: #eef8f1; }
.join-result.z-consider { border-color: #d4a017; background: #fff8e1; }
.join-result.z-risky { border-color: #e07b16; background: #fff1e4; }
.join-result.z-avoid { border-color: #a3201f; background: #fdecea; }
.join-zone { font-size: 24px; font-weight: 900; }
.join-note { color: var(--muted); margin: 2px 0 8px; font-size: 14px; }
.join-result b.neg { color: #a3201f; }

/* Printer */
.event-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.event-row .event { flex: 1; min-width: 0; }
.printer-btn { flex: none; font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.15); color: var(--cream); }
.printer-btn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e9a29a; margin-right: 6px; vertical-align: 1px; }
.printer-btn.on .dot { background: #7be08f; }
.printer-steps { margin: 0 0 10px; padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }

/* Login, roles, sync status */
body.logged-out .tabs, body.logged-out .event-row button { display: none; }
body.role-stall .tab[data-view="dash"], body.role-stall .tab[data-view="costs"] { display: none; }
.sync-btn { flex: none; font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.15); color: var(--cream); white-space: nowrap; }
.sync-btn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #7be08f; margin-right: 6px; vertical-align: 1px; }
.sync-btn.syncing .dot { background: #f5c518; }
.sync-btn.offline .dot, .sync-btn.error .dot { background: #e9a29a; }
.login { margin-top: 24px; }
.login .btn { width: 100%; margin-top: 8px; }
