:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --dim: #98a0b3;
  --accent: #4ade80;
  --accent-dim: #16311f;
  --danger: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Author `display` rules (e.g. .addForm's grid) outrank the UA stylesheet's
   [hidden] { display: none }, which silently breaks every hidden element.
   This must stay. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- head ---------- */
.head { margin-bottom: 16px; }
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--dim); font-size: .875rem; }

/* ---------- meter ---------- */
.meter {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 18px 18px;
  text-align: center;
  margin-bottom: 16px;
}

.cost {
  font-size: clamp(2.6rem, 13vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.meter.live .cost { color: var(--accent); }

.meterRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0 18px;
}
.stat { display: flex; flex-direction: column; gap: 3px; }
.statLabel { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.statVal { font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.controls { display: flex; gap: 10px; }
.controls .btn { flex: 1; }

.hint { margin: 12px 0 0; font-size: .78rem; color: var(--dim); min-height: 1em; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 14px 16px;
  min-height: 48px;
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btnPrimary { background: var(--accent); border-color: var(--accent); color: #08210f; }
.btnPrimary.running { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.btnGhost { background: transparent; color: var(--dim); }

.btnAdd {
  width: 44px; height: 44px; min-height: 44px;
  padding: 0;
  font-size: 1.6rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); border-color: var(--accent); color: #08210f;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
/* When the add form is open the + becomes an × that closes it, so the button
   never looks like it only does one of the two things. */
.btnAdd.open {
  background: var(--panel2);
  border-color: var(--line);
  color: var(--text);
}

.btnFull { width: 100%; }

.btnIcon {
  width: 56px; height: 48px; min-height: 48px;
  padding: 0; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.btnIcon svg { display: block; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panelHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 { font-size: .95rem; margin: 0; font-weight: 600; }
.count {
  display: inline-block; margin-left: 4px; padding: 1px 8px;
  border-radius: 999px; background: var(--panel2); color: var(--dim);
  font-size: .78rem; font-variant-numeric: tabular-nums;
}

/* ---------- form ---------- */
.addForm { margin-top: 14px; display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
label { font-size: .8rem; color: var(--dim); }
.opt { opacity: .7; }

input[type="text"], input[type="number"], select {
  font: inherit;
  width: 100%;
  padding: 13px 12px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  appearance: none;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.moneyInput { position: relative; display: flex; align-items: center; }
.moneyInput .dollar {
  position: absolute; left: 12px; color: var(--dim); font-weight: 600; pointer-events: none;
}
.moneyInput input { padding-left: 28px; padding-right: 56px; }
.moneyInput .suffix {
  position: absolute; right: 12px; color: var(--dim); font-size: .82rem; pointer-events: none;
}
#burdenWrap input { padding-right: 12px; }

.formActions { display: flex; gap: 10px; margin-top: 2px; }
.formActions .btn { flex: 1; }
.err { color: var(--danger); font-size: .82rem; margin: 0; }

/* ---------- list ---------- */
.list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.list:empty { margin: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
.rowMain { flex: 1; min-width: 0; }
.rowName { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowMeta { font-size: .76rem; color: var(--dim); margin-top: 2px; }
.rowRate { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.del {
  background: none; border: 0; color: var(--dim);
  font-size: 1.5rem; line-height: 1;
  width: 40px; height: 40px; min-height: 40px;
  cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.del:hover, .del:focus-visible { color: var(--danger); }

.empty { color: var(--dim); font-size: .85rem; margin: 14px 0 0; }

/* ---------- "added" confirmation ---------- */
/* The list sits below a tall form, so a new attendee lands off-screen on a
   phone. This is pinned to the viewport so the confirmation is seen no matter
   where the page is scrolled, and it can't swallow a tap. */
.added {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 24px);
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  font-size: .82rem;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  animation: popIn .18s ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%); }
}
.row.justAdded { animation: rowGlow 1.6s ease-out; }
@keyframes rowGlow {
  0%   { border-color: var(--accent); background: var(--accent-dim); }
  100% { border-color: var(--line); background: var(--panel2); }
}
.count.bump { animation: countBump .45s ease-out; }
@keyframes countBump {
  0%   { background: var(--accent); color: #08210f; transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { background: var(--panel2); color: var(--dim); transform: scale(1); }
}

/* ---------- invoice ---------- */
.invoicePanel { margin-top: 14px; display: grid; gap: 12px; }
.invActions { display: flex; justify-content: flex-end; gap: 10px; }
.btnPdf { font-size: .8rem; font-weight: 700; letter-spacing: .04em; }

.invoiceDoc {
  background: #fff;
  color: #14161c;
  border-radius: 10px;
  padding: 16px;
  font-size: .82rem;
  line-height: 1.45;
}
.invHead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.invTitle { font-size: 1.05rem; font-weight: 700; letter-spacing: .08em; }
.invMeta { text-align: right; color: #5b616e; font-size: .74rem; white-space: nowrap; }
.invParties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 14px 0 12px;
}
.invLabel {
  display: block; font-size: .64rem; text-transform: uppercase;
  letter-spacing: .07em; color: #7b8291;
}
.invParty { font-weight: 600; word-break: break-word; }
.invTable { width: 100%; border-collapse: collapse; }
.invTable th, .invTable td {
  text-align: left; padding: 8px 0; border-bottom: 1px solid #e2e5ea; vertical-align: top;
}
.invTable thead th { font-size: .64rem; text-transform: uppercase; letter-spacing: .07em; color: #7b8291; }
.invTable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invTable tfoot th { border-bottom: 0; border-top: 2px solid #14161c; font-size: .95rem; padding-top: 10px; }
.invSub { color: #5b616e; font-size: .74rem; margin-top: 2px; }

/* ---------- settings ---------- */
details { font-size: .9rem; }
summary { cursor: pointer; font-weight: 600; font-size: .95rem; padding: 2px 0; }
details[open] summary { margin-bottom: 14px; }
details .field + .field { margin-top: 14px; }
.note { font-size: .76rem; color: var(--dim); margin: 2px 0 0; line-height: 1.45; }
.checkLine { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .85rem; }
.checkLine input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

/* ---------- foot ---------- */
.foot { text-align: center; color: var(--dim); font-size: .75rem; }
.foot p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- print: the invoice only ----------
   visibility (not display) is used so the rule can't be beaten by the
   [hidden] { display: none !important } guard above or by author display rules. */
@media print {
  html, body { background: #fff; color: #000; }

  /* Belt: nothing paints unless it is part of the invoice document. */
  body * { visibility: hidden; }
  #invoiceDoc, #invoiceDoc * { visibility: visible; }

  /* Braces: and nothing else takes up space, so the PDF is one page rather
     than one invoice followed by several blank sheets. Do NOT swap this for
     position:absolute on #invoiceDoc — the hidden-but-laid-out rest of the
     page still paginates and the invoice ends up on a page of its own. */
  .wrap > *:not(#invoiceSection) { display: none !important; }
  #invoiceSection > .panelHead,
  #invoiceBtn,
  #invoicePanel > .field,
  #invoicePanel > .err,
  #invoicePanel > .invActions,
  #invoicePanel > .note { display: none !important; }

  .wrap { padding: 0; max-width: none; }
  #invoiceSection { margin: 0; padding: 0; border: 0; background: #fff; }
  #invoicePanel { margin: 0; gap: 0; }
  #invoiceDoc { padding: 0; border-radius: 0; font-size: 11pt; }
}
