:root {
  --paper: #fbfaf7;
  --paper-edge: #f1efe8;
  --ink: #1a1a17;
  --ink-soft: #6b6a63;
  --line: #e2e0d6;
  --amber: #e8a53d; /* claimed / active */
  --teal: #2d7d6e; /* paid / settled */
  --rust: #c2553d; /* remaining / error */
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --disp: "Space Grotesk", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #efece3;
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  /* viewport-fit=cover: keep painted background behind notch/home indicator */
  background: #e7e3d8;
}

body {
  background-image: radial-gradient(circle at 50% 0, #f6f3ea, #e7e3d8);
  min-height: 100dvh;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    max(14px, env(safe-area-inset-right, 0px))
    calc(96px + env(safe-area-inset-bottom, 0px))
    max(14px, env(safe-area-inset-left, 0px));
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

#app { max-width: 460px; margin: 0 auto; width: 100%; }

/* ---- the receipt slip ---------------------------------------------------- */
.slip {
  position: relative;
  background: var(--paper);
  border-radius: 3px;
  padding: 26px 20px 22px;
  box-shadow: 0 1px 0 #fff inset, 0 18px 40px -22px rgba(26, 26, 23, 0.5);
  background-image: repeating-linear-gradient(
    var(--paper) 0 27px,
    #f7f4ec 27px 28px
  );
}
.slip::before,
.slip::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 9px;
  background: radial-gradient(circle at 7px 9px, transparent 7px, var(--paper) 8px) repeat-x;
  background-size: 14px 14px;
}
.slip::before { top: -8px; transform: rotate(180deg); }
.slip::after { bottom: -8px; }

/* ---- masthead ------------------------------------------------------------ */
.mast { text-align: center; padding-bottom: 14px; border-bottom: 1.5px dashed var(--line); }
.mast h1 {
  font-family: var(--disp);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 1.05rem;
  margin: 0 0 4px;
}
.mast .venue { font-family: var(--mono); font-size: 0.92rem; }
.mast .sub { color: var(--ink-soft); font-size: 0.74rem; letter-spacing: 0.04em; margin-top: 3px; }
.brand-badge {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- generic rows -------------------------------------------------------- */
.row { display: flex; align-items: baseline; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.eyebrow {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 18px 0 8px;
}

/* ---- item lines ---------------------------------------------------------- */
.item { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.item-head { display: flex; align-items: baseline; gap: 10px; }
.item-name { font-family: var(--mono); font-weight: 500; font-size: 0.96rem; }
.item-price { color: var(--ink-soft); font-size: 0.76rem; }
.item-line-total { font-family: var(--mono); margin-left: auto; font-weight: 500; }

.meter { height: 6px; border-radius: 6px; background: var(--paper-edge); margin: 9px 0 8px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.meter > span { display: block; height: 100%; background: var(--amber); transition: width 0.25s ease; }
.meter.full > span { background: var(--teal); }

.claimants { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fdf3df;
  border: 1px solid #f0dcab;
  color: #8a5a12;
  white-space: nowrap;
}
.chip.me { background: var(--amber); border-color: var(--amber); color: #2a1c00; font-weight: 700; }
.chip .amt { opacity: 0.7; margin-left: 4px; }

/* claim controls */
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: stretch; border: 1.5px solid var(--ink); border-radius: 9px; overflow: hidden; }
.stepper button { border: 0; background: var(--paper); font-size: 1.1rem; width: 34px; cursor: pointer; font-family: var(--mono); }
.stepper button:active { background: var(--ink); color: var(--paper); }
.stepper .val { min-width: 34px; display: grid; place-items: center; font-family: var(--mono); font-weight: 700; border-left: 1.5px solid var(--ink); border-right: 1.5px solid var(--ink); }
.fracs { display: inline-flex; gap: 6px; }
.frac {
  font-family: var(--mono);
  font-size: 0.92rem;
  width: 34px; height: 34px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  cursor: pointer;
}
.frac[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: #2a1c00; font-weight: 700; }

/* ---- totals -------------------------------------------------------------- */
.totals { margin-top: 14px; padding-top: 12px; border-top: 1.5px dashed var(--line); }
.totals .grand { font-family: var(--disp); font-weight: 700; font-size: 1.15rem; }
.unclaimed { color: var(--rust); }

/* ---- participant ledger (host) ------------------------------------------- */
.ledger-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-soft); flex: none; }
.dot.marked { background: var(--amber); }
.dot.confirmed { background: var(--teal); }
.status { font-family: var(--mono); font-size: 0.7rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---- buttons ------------------------------------------------------------- */
button { font-family: var(--body); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--disp); font-weight: 600; font-size: 0.95rem;
  padding: 13px 18px; border-radius: 11px; border: 1.5px solid var(--ink);
  background: var(--ink); color: var(--paper); cursor: pointer; width: 100%;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn.small { width: auto; padding: 8px 12px; font-size: 0.82rem; }
.btn.teal { background: var(--teal); border-color: var(--teal); }
.btn.danger { background: transparent; color: #b3261e; border-color: #b3261e; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- sticky pay bar ------------------------------------------------------ */
.paybar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(251, 250, 247, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.paybar .inner { max-width: 460px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.paybar .owe { line-height: 1.1; }
.paybar .owe small { display: block; font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
.paybar .owe .amt { font-family: var(--disp); font-weight: 700; font-size: 1.3rem; }
.paybar .btn { width: auto; flex: 1; max-width: 200px; margin-left: auto; }

/* ---- forms --------------------------------------------------------------- */
label { display: block; font-size: 0.78rem; font-weight: 600; margin: 12px 0 5px; }
label.check-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 0 0;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
}
label.check-label input[type="checkbox"] {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.1rem 0 0;
  accent-color: var(--teal);
}
label.check-label span {
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
input {
  width: 100%; font-family: var(--mono); font-size: 1rem;
  padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
}
input:focus-visible, .frac:focus-visible, .btn:focus-visible, button:focus-visible {
  outline: 3px solid var(--amber); outline-offset: 2px;
}
.field-row { display: flex; gap: 8px; }
.item-edit {
  display: grid;
  grid-template-columns: 1fr minmax(72px, 0.42fr) minmax(44px, 0.22fr) auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.item-edit input { padding: 10px 9px; font-size: 1rem; min-height: 44px; }
.x { border: 0; background: none; color: var(--rust); font-size: 1.2rem; cursor: pointer; }
.hint { font-size: 0.72rem; color: var(--ink-soft); margin-top: 4px; }
.hint code { font-family: var(--mono); font-size: 0.68rem; background: var(--paper-edge); padding: 1px 5px; border-radius: 4px; }

textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  min-height: 120px;
}

/* ---- bill import --------------------------------------------------------- */
.import-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.import-tab {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 8px 6px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.import-tab.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.import-panel { margin-bottom: 4px; }
.scan-actions { display: flex; gap: 8px; margin-top: 8px; }
.bill-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.bill-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.bill-thumb img { width: 100%; height: 100%; object-fit: cover; }
.bill-thumb-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(26, 26, 23, 0.75);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}
.prompt-box {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fff;
}
.prompt-box summary {
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}
.prompt-steps {
  margin: 8px 0;
  padding-left: 1.2rem;
  font-size: 0.76rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
.prompt-text {
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
  margin: 8px 0;
  padding: 8px;
  background: var(--paper-edge);
  border-radius: 8px;
}
.cam-sheet video {
  width: 100%;
  border-radius: 10px;
  background: #000;
  max-height: 50vh;
  object-fit: cover;
}
.cam-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

/* ---- overlay / sheet ----------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(26, 26, 23, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.sheet {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 100%;
  max-width: 380px;
  margin: auto 0;
  background: var(--paper);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  touch-action: manipulation;
}
body.gate-open { overflow: hidden; overscroll-behavior: none; }
.sheet h2 { font-family: var(--disp); margin: 0 0 4px; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 12px; border: 1px solid var(--line); margin: 14px 0; }
.qr svg { width: 220px; height: 220px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 0.86rem; }
.kv .k { color: var(--ink-soft); }
.kv .v { font-family: var(--mono); text-align: right; word-break: break-all; }
.turnstile-holder:not(:empty) { margin-top: 16px; display: flex; justify-content: center; }
.copyrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.open-bank { text-decoration: none; margin: 4px 0 14px; }
.paylink-block { margin: 0 0 14px; text-align: center; }
.paylink-btn { width: 100%; text-decoration: none; }
.bank-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bank-btn { padding: 10px 6px; font-size: 0.78rem; text-decoration: none; text-align: center; }
.bank-btn.preferred { box-shadow: inset 0 0 0 2px var(--teal); }

/* ---- toast --------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px;
  font-size: 0.85rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 40; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--rust); }

.center { text-align: center; }
.stack > * + * { margin-top: 10px; }
.spin { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: sp 0.8s linear infinite; margin: 30px auto; }
@keyframes sp { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition: none !important; }
}

/* ---- top bar: language switch + optional account chip -------------------- */
.topbar {
  max-width: 460px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}
.lang-switch { display: inline-flex; gap: 2px; background: var(--paper-edge); border-radius: 999px; padding: 3px; }
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 0.72rem/1 var(--disp);
  letter-spacing: 0.04em;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
}
.lang-btn.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px -1px rgba(26, 26, 23, 0.3); }
.account-chip {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: 600 0.78rem/1 var(--disp);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-chip.ghost { color: var(--ink-soft); }

/* ---- region switch (create form) ---------------------------------------- */
.region-switch { display: inline-flex; gap: 2px; background: var(--paper-edge); border-radius: 999px; padding: 3px; }
.region-btn {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 0.8rem/1 var(--disp);
  letter-spacing: 0.02em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.region-btn.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px -1px rgba(26, 26, 23, 0.3); }

/* ---- presence ("who's at the table") ------------------------------------ */
.present-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 2px; }
.pchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.pchip.off { opacity: 0.5; }
.pdot { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1.5px var(--ink-soft); }
.pdot.on { background: var(--teal); box-shadow: inset 0 0 0 1.5px var(--teal); }
.pdot.off { background: transparent; }
.ledger-row .grow .pdot { display: inline-block; margin-right: 7px; vertical-align: middle; }

/* Phase 6 — B2B merchant dashboard + table entry (kept off the pristine guest flow). */
.card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.row.between { justify-content: space-between; align-items: center; }
select.input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); font: inherit; }
input[type='color'] { width: 100%; height: 42px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.menu-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.fiscal-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; font-size: 0.86rem; color: var(--ink-soft); }
.fiscal-banner.ok { border-style: solid; color: var(--ink); }

/* ---- native shell (Capacitor): full-width phone layout ------------------- */
html.native {
  background: var(--paper);
}

html.native body {
  background: var(--paper);
  background-image: none;
  padding:
    calc(10px + env(safe-area-inset-top, 0px))
    0
    calc(88px + env(safe-area-inset-bottom, 0px));
}

html.native #app,
html.native .topbar,
html.native .paybar .inner {
  max-width: none;
  width: 100%;
}

html.native #app,
html.native .topbar {
  padding-left: 16px;
  padding-right: 16px;
}

html.native .topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 0 8px;
  padding-top: 6px;
  padding-bottom: 10px;
  background: rgba(251, 250, 247, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

html.native .slip {
  width: 100%;
  border-radius: 0;
  box-shadow: none;
  padding-left: 16px;
  padding-right: 16px;
}

html.native .slip::before,
html.native .slip::after {
  display: none;
}

html.native .paybar {
  padding-left: 16px;
  padding-right: 16px;
}

html.native .btn,
html.native .lang-btn,
html.native .region-btn,
html.native .account-chip {
  min-height: 44px;
}

html.native .stepper button,
html.native .frac {
  min-width: 44px;
  min-height: 44px;
}

html.native .stepper .val {
  min-width: 44px;
}

html.native #toast {
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

html.native .sheet {
  max-width: none;
}

@media (max-width: 390px) {
  .item-edit {
    grid-template-columns: 1fr 1fr auto;
  }
  .item-edit .i-name {
    grid-column: 1 / -1;
  }
  .mast h1 { font-size: 0.98rem; letter-spacing: 0.14em; }
  .slip { padding: 22px 16px 18px; }
}
