:root {
  --ink: #404041;
  --muted: #74787d;
  --line: #e2e3e5;
  --bg: #f4f4f5;
  --card: #fff;
  --accent: #ce8e45;
  --accent-ink: #8a5a20;
  --danger: #b3261e;
  --ok: #2e7d4f;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: .2rem 0; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
a { color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; letter-spacing: .02em; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
input, textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
input { min-width: 0; min-height: 44px; }
::placeholder { color: #b9bcc0; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1.3fr; }
.row > label { min-width: 0; }
html { scroll-padding-bottom: 90px; } /* keep focused fields clear of the sticky action bar */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; text-decoration: none;
  color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.top .btn { min-height: 36px; border: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.link { background: none; border: 0; padding: 8px 0; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }
.danger { color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.actions form { display: contents; }
.actions .btn:not(.big) { flex: 1; }
.actions.sticky {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; margin: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(244, 244, 245, .95); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
@media (min-width: 700px) {
  .actions.sticky { position: static; padding: 0; background: none; border: 0; backdrop-filter: none; }
  .actions.sticky .btn { flex: 0 1 auto; }
}

/* list */
.owed { margin: 4px 0 12px; color: var(--muted); }
.owed strong { color: var(--ink); }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: grid; grid-template-columns: 3em 1fr auto; gap: 10px; align-items: center; padding: 14px 16px; text-decoration: none; }
.list a:active { background: var(--bg); }
.no { font-weight: 700; font-variant-numeric: tabular-nums; }
.who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { display: block; color: var(--muted); font-size: .8rem; }
.sum { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.sum .tag { display: block; margin-top: 2px; margin-left: auto; width: fit-content; }
.tag { font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); vertical-align: middle; }
.tag.paid { background: #e3f3e9; color: var(--ok); }
.tag.overdue { background: #fbe4e2; color: var(--danger); }
.tag.issued { background: #fbf0e2; color: var(--accent-ink); }
.empty, .foot { text-align: center; color: var(--muted); margin: 24px 0; }

/* edit */
.search { position: relative; margin-bottom: 14px; }
.results {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 4; margin: 4px 0 0; padding: 0; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 60vh; overflow: auto;
}
.results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.results button:hover, .results button:focus { background: var(--bg); outline: none; }
.results li + li { border-top: 1px solid var(--line); }
.results small { display: block; color: var(--muted); }
.line { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 14px 0 4px; }
.line:first-child { border-top: 0; padding-top: 0; }
.line-foot { display: flex; justify-content: space-between; align-items: center; }
.line-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.line:only-child .remove-line { visibility: hidden; }
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 0 0; padding-top: 12px; border-top: 2px solid var(--ink); font-size: 1.1rem; }
.chips { display: flex; gap: 8px; }
.chip { flex: 1; min-height: 40px; font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 99px; cursor: pointer; color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.error { background: #fbe4e2; color: var(--danger); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.error p { margin: 4px 0; }
.note { background: #fbf0e2; border-radius: 8px; padding: 10px 12px; }

/* view */
.kicker { margin: 0; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); margin: 4px 0 12px; }
.dates { display: flex; gap: 24px; margin: 12px 0; }
.dates dt { font-size: .8rem; color: var(--muted); }
.dates dd { margin: 0; font-weight: 600; }
.lines-view { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lines-view td { padding: 10px 0; border-top: 1px solid var(--line); vertical-align: top; }
.lines-view td + td { padding-left: 8px; }
.lines-view small { color: var(--muted); }
.lines-view .grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 1.1rem; }
.r { text-align: right; white-space: nowrap; }

/* login */
.login { max-width: 360px; margin: 15vh auto 0; }
.login h1 { margin-bottom: 16px; }
.login .btn { width: 100%; }
.tag.credit, .tag.credited { background: #ececef; color: var(--muted); }
