:root {
  --bg: #f4f5f7;
  --card: #fff;
  --ink: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #0f766e;
  --accent-ink: #fff;
  --pos: #15803d;
  --neg: #b91c1c;
  --chip: #eef2f6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --ink: #e6e9ef; --muted: #9aa3b2; --line: #2b313c;
    --accent: #2dd4bf; --accent-ink: #062320; --pos: #4ade80; --neg: #f87171; --chip: #252b36;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { color: var(--ink); }
.topbar nav .me { color: var(--muted); }

main { max-width: 1000px; margin: 0 auto; padding: 1rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.card.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
.notes { white-space: normal; }

.row-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.row-head h1, .row-head h2 { margin: 0; }
.crumbs { margin-bottom: .75rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.stat .big, .big { font-size: 1.5rem; font-weight: 700; }

.trip-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card.trip { display: block; color: var(--ink); margin: 0; }
.card.trip:hover { border-color: var(--accent); text-decoration: none; }
.trip-name { font-weight: 600; font-size: 1.1rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--muted); }
.nowrap { white-space: nowrap; }
.tag {
  display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 99px;
  background: var(--chip); color: var(--muted); font-weight: 500; vertical-align: middle;
}

/* Tables */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
tfoot th { color: var(--ink); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.focus td { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* Forms */
label { display: block; margin-bottom: .75rem; font-weight: 500; }
label.inline { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .55rem .6rem; font: inherit;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { display: inline-block; width: auto; margin: 0; accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1rem; padding: .75rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

button, .button {
  display: inline-block; padding: .5rem .9rem; font: inherit; font-weight: 500; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.button:hover, button:hover { text-decoration: none; filter: brightness(.97); }
.primary, button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.danger { background: transparent; color: var(--neg); border-color: var(--neg); }
.button.small, button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: none; padding: 0; color: var(--accent); font-size: .85rem; }
button.link.danger { color: var(--neg); font-size: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row-actions { flex-wrap: nowrap; justify-content: flex-end; gap: .35rem; }
@media (max-width: 560px) { .row-actions { flex-direction: column; align-items: stretch; } .row-actions .button { text-align: center; } }
.row-actions form { display: inline; margin: 0; }
.danger-zone { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.inline-form { display: flex; gap: .5rem; }
.inline-form input { margin: 0; }

.flash { padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; background: color-mix(in srgb, var(--pos) 14%, var(--card)); }
.flash.err { background: color-mix(in srgb, var(--neg) 14%, var(--card)); }
.invite .copy { font-family: ui-monospace, monospace; font-size: .85rem; }

/* Person chips (who an item is for) */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .4rem 0; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: .3rem .6rem;
  background: var(--chip); border-radius: 99px; font-weight: 400; cursor: pointer; user-select: none;
}
.chip:has(input:checked) { background: color-mix(in srgb, var(--accent) 22%, var(--chip)); }
.chip input[type=number] { width: 4.2rem; margin: 0; padding: .15rem .3rem; }
.chip-tools { font-size: .85rem; color: var(--muted); }

/* Expense form: each line item is one compact row; its people chips open
   below it (one row at a time) from the "who" button. */
.item { border: 1px solid var(--line); border-radius: var(--radius); padding: .45rem .55rem; margin: .4rem 0; }
.item.rest { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.item.open { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.item-head {
  display: grid; align-items: center; gap: .4rem;
  grid-template-columns: minmax(0, 1fr) 6.5rem minmax(0, 13rem) 1.6rem;
  grid-template-areas: "desc amt who x";
}
.item-head input { margin: 0; }
.item-head .desc { grid-area: desc; min-width: 0; }
.item-head .amt { grid-area: amt; text-align: right; }
.item-head span.amt { font-weight: 600; }
.item-head .who { grid-area: who; }
.item-head .remove { grid-area: x; justify-self: center; }
.who {
  display: flex; align-items: center; justify-content: space-between; gap: .3rem; min-width: 0; width: 100%;
  padding: .5rem .6rem; font-size: .9rem; font-weight: 400; background: var(--chip); border-color: transparent;
}
.who-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who.empty { color: var(--neg); border-color: var(--neg); background: transparent; }
.caret { color: var(--muted); transition: transform .15s; }
.item.open .caret { transform: rotate(180deg); }
.item-who { padding-top: .35rem; }
.item-who .chips { margin: 0; }
.js .item:not(.open) .item-who { display: none; }

@media (max-width: 560px) {
  .item-head {
    grid-template-columns: minmax(0, 1fr) 5.5rem 1.6rem;
    grid-template-areas: "desc amt x" "who who who";
  }
  .item.rest .item-head { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "desc amt" "who who"; }
}
.preview { margin: .5rem 0 1rem; }
ul.splits { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .25rem 1rem; }
ul.splits li { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: .15rem 0; }

/* Settle up */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a { padding: .3rem .7rem; color: var(--ink); font-size: .9rem; }
.seg a.on { background: var(--accent); color: var(--accent-ink); }
ul.transfers { list-style: none; margin: 0; padding: 0; }
ul.transfers li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
ul.transfers li > span:first-child { flex: 1; }
ul.transfers li.mine { font-weight: 600; }

ul.history { list-style: none; padding: 0; margin: 0; }
ul.history li { padding: .25rem 0; border-bottom: 1px dotted var(--line); }
ul.history .muted { margin-right: .5rem; }

@media (max-width: 560px) {
  main { padding: .6rem; }
  .card { padding: .8rem; }
  table.expenses th:nth-child(3), table.expenses td:nth-child(3) { display: none; }
}

/* Filter chips (links) and the General card on the home page */
.chips.filter { margin: 0 0 1rem; }
a.chip { color: var(--ink); }
a.chip:hover { text-decoration: none; filter: brightness(.95); }
a.chip.on { background: var(--accent); color: var(--accent-ink); }
.card.trip.general-card { margin-bottom: 1rem; }   /* beat .card.trip { margin: 0 } */

.writeoff-all { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .75rem; }
.writeoff-all label { margin: 0; }

/* People pickers: occasional people (.more) stay hidden until "Show everyone"
   is ticked, unless they're already selected. */
form:not(:has(.show-all-toggle:checked)) .chip.more:not(:has(input[type=checkbox]:checked)):not(.on) { display: none; }
.show-all { color: var(--muted); }

/* Receipt photos on the expense form */
.receipts { margin: .75rem 0 1rem; }
.receipt-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: .5rem; }
.receipt-row:empty, .receipt-previews:empty { display: none; }
.receipt-previews { display: contents; }
.receipt { display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.receipt img { width: 88px; height: 88px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--chip); }
.receipt.new img { border-color: var(--accent); }
.receipt label { margin: 0; }
.receipt-add { position: relative; cursor: pointer; margin-right: .5rem; }
.receipt-add input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; margin: 0; }
.receipt-badge { font-size: .85rem; margin-left: .25rem; text-decoration: none; }
.receipt-ph { width: 88px; height: 88px; display: grid; place-items: center; font-size: 2rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--chip); }

/* Anchored sections (#edit, #settle, #receipts...) shouldn't land under the sticky top bar. */
[id] { scroll-margin-top: 4.5rem; }

/* Inline "edit person" panel on the People page */
.edit-row > td { padding: .75rem .5rem 1rem; background: color-mix(in srgb, var(--accent) 4%, transparent); }
.edit-person .actions { margin-top: .75rem; }
.edit-row .danger-zone { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
