:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-soft: #dcfce7;
  --bg: #f6f7f5;
  --card: #ffffff;
  --ink: #14201a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 6px 20px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  line-height: 1.45;
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

/* --- Typography / generic --- */
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
a { color: var(--green-dark); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* --- Top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; margin: 0 -16px 16px;
  background: rgba(246, 247, 245, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; color: var(--green-dark); }
.brand .logo { font-size: 22px; }
.topbar .back { background: none; border: none; font-size: 15px; color: var(--green-dark); font-weight: 600; padding: 6px; cursor: pointer; }

/* --- Cards --- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 22px 4px 8px; text-transform: uppercase; letter-spacing: .03em; }

/* --- Buttons --- */
button { font-family: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--green); color: #fff; border: none; border-radius: 11px;
  padding: 13px 18px; font-size: 16px; font-weight: 700; cursor: pointer; width: 100%;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.985); }
.btn:hover { background: var(--green-dark); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f3f4f6; }
.btn.ghost { background: transparent; color: var(--green-dark); width: auto; padding: 8px 10px; }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.btn.sm { padding: 9px 13px; font-size: 14px; width: auto; }
.btn.inline { width: auto; }

/* --- Forms --- */
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 5px; }
input, textarea {
  width: 100%; padding: 13px 14px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 11px; background: #fff; color: var(--ink); font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
textarea { resize: vertical; min-height: 70px; }

/* --- Landing / auth --- */
.hero { text-align: center; padding: 30px 0 10px; }
.hero .logo { font-size: 54px; }
.hero h1 { font-size: 30px; margin-top: 8px; }
.hero p { color: var(--muted); margin: 6px 0 0; }
.tabs { display: flex; gap: 6px; background: #eef0ee; padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tabs button { flex: 1; border: none; background: none; padding: 10px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* --- Event list --- */
.event-row { display: block; text-decoration: none; color: inherit; }
.event-row .name { font-weight: 700; font-size: 17px; }
.badge { display: inline-block; background: var(--green-soft); color: var(--green-dark); font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }

/* --- Line items --- */
.line {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff;
}
.line.unallocated { border-color: #fde68a; background: var(--warn-soft); }
.line .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.line .lname { font-weight: 700; }
.line .price { font-weight: 800; white-space: nowrap; }
.line .per { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fff; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.chip.me { box-shadow: 0 0 0 2px var(--green-soft); }
.chip[disabled] { cursor: default; opacity: .9; }
.chip .x { color: inherit; opacity: .7; }
.chip .cl { white-space: nowrap; }
.chip .step {
  border: none; background: rgba(255, 255, 255, .28); color: inherit;
  width: 24px; height: 24px; min-width: 24px; border-radius: 50%; padding: 0;
  font-size: 17px; line-height: 1; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.chip .step:hover { background: rgba(255, 255, 255, .45); }
.warn-text { color: var(--warn); font-weight: 600; }

/* --- Summary --- */
.sumrow { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); }
.sumrow:last-child { border-bottom: none; }
.sumrow .who { font-weight: 700; }
.sumrow .lines { font-size: 12px; color: var(--muted); }
.total-line { display: flex; justify-content: space-between; font-size: 19px; font-weight: 800; padding-top: 8px; }
.pill-ok { color: var(--green-dark); font-weight: 700; }
.pill-warn { color: var(--warn); font-weight: 700; }

/* --- Sticky footer (viewer total) --- */
.footbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
.footbar .inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.footbar .you { flex: 1; }
.footbar .you .lbl { font-size: 12px; color: var(--muted); }
.footbar .you .amt { font-size: 22px; font-weight: 800; }

/* --- Receipt image --- */
.receipt-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; }

/* --- QR --- */
.qr-box { text-align: center; }
.qr-box img { width: 240px; max-width: 80%; border-radius: 12px; border: 1px solid var(--line); }
.link-field { display: flex; gap: 8px; margin-top: 10px; }
.link-field input { font-size: 13px; }

/* --- Modal --- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: #fff; width: 100%; max-width: 640px; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto;
}
@media (min-width: 560px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; margin: 0 16px; } }
.modal h2 { margin-bottom: 4px; }

/* --- Toast --- */
.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 11px 18px; border-radius: 11px; font-size: 14px;
  z-index: 60; box-shadow: var(--shadow); max-width: 90%; text-align: center;
}
.toast.err { background: var(--danger); }

.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.dark { border-color: var(--line); border-top-color: var(--green); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 40px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }
.tbl-head { display: flex; gap: 6px; padding: 0 2px 6px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.tbl-head .grow { flex: 1; min-width: 0; }
.tbl-head .ac { width: 60px; text-align: center; }
.tbl-head .qc { width: 46px; text-align: center; }
.tbl-head .sc { width: 70px; text-align: right; }
.tbl-head .xc { width: 34px; }
.itemline { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.itemline input.n { flex: 1; min-width: 0; }
.itemline input.a { width: 60px; text-align: right; padding-left: 6px; padding-right: 6px; }
.itemline input.q { width: 46px; text-align: center; padding-left: 4px; padding-right: 4px; }
.itemline .s { width: 70px; text-align: right; font-weight: 700; font-size: 14px; white-space: nowrap; }
.itemline button { flex: 0 0 auto; width: 34px; padding-left: 0; padding-right: 0; }
.reconcile { background: #f3f4f6; border-radius: 11px; padding: 11px 13px; margin-bottom: 14px; }
