/* ---- design tokens (adapted from bookshelf, green accent) ----------- */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efedea;
  --border: #e4e1db;
  --ink: #1c1a17;
  --muted: #74706a;
  --accent: #2f6f4f;
  --accent-hover: #285f43;
  --accent-ink: #ffffff;
  --accent-weak: rgba(47, 111, 79, .12);
  --pos: #2f6b46;
  --neg: #b23b2e;
  --warn-bg: #fbeecc;
  --warn-ink: #7a4f05;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.07);
  --radius: 16px;
  --radius-sm: 11px;
  --bar: rgba(255,255,255,.78);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #232127;
    --surface-2: #2b2930;
    --border: #38353d;
    --ink: #f0ede8;
    --muted: #a39e98;
    --accent: #5fb98a;
    --accent-hover: #6fcf97;
    --accent-ink: #0e1a13;
    --accent-weak: rgba(95, 185, 138, .16);
    --pos: #6fcf97;
    --neg: #f08b7e;
    --warn-bg: #3a3320;
    --warn-ink: #f0d68a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.45);
    --bar: rgba(25,24,28,.72);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { letter-spacing: -.02em; }
h2 { margin: 1.6rem 0 .6rem; font-size: 1.05rem; }

/* ---- top bar -------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 1.5rem);
  padding-top: max(.7rem, env(safe-area-inset-top));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  color: var(--ink); font-weight: 700; font-size: 1.08rem;
  text-decoration: none; letter-spacing: -.01em;
}
.brand::before { content: ""; display: inline-block; width: 1.5em; height: 1.5em;
  vertical-align: -.35em; background: url("icons/icon.svg") center/contain no-repeat; }
.topbar nav a {
  color: var(--muted); text-decoration: none; font-size: .92rem; font-weight: 500;
  padding: .4rem .7rem; border-radius: 999px;
}
.topbar nav a:hover { color: var(--ink); background: var(--surface-2); }

main { max-width: 720px; margin: 0 auto; padding: clamp(1rem, 4vw, 1.6rem);
  padding-bottom: calc(clamp(1rem, 4vw, 1.6rem) + env(safe-area-inset-bottom, 0px)); }

/* ---- forms / cards -------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem;
  display: flex; flex-direction: column; gap: .8rem;
  box-shadow: var(--shadow-sm);
}
.stack { display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; font-weight: 500; color: var(--muted); }
label.cb { flex-direction: row; align-items: center; gap: .5rem; font-size: .95rem; color: var(--ink); }
label.cb input { width: auto; }
input, select, textarea {
  /* 16px keeps iOS Safari from auto-zooming the viewport on focus. These controls
     sit inside <label> (.8rem), so an inherited size would be ~12.8px and trigger
     the zoom. */
  font-family: inherit; font-size: 16px; color: var(--ink); width: 100%;
  padding: .6rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak);
}
.row { display: flex; gap: .8rem; align-items: flex-end; }
.row > input, .row > select { flex: 1; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 999px;
  padding: .55rem 1.1rem; background: var(--surface-2); color: var(--ink);
  text-decoration: none;
}
button:active, .btn:active { transform: translateY(1px); }
button.primary, button[type="submit"]:not([name]), .btn.primary {
  background: var(--accent); color: var(--accent-ink);
}
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--neg); color: #fff; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---- lists ---------------------------------------------------------- */
.cards, .bills, .balances, .suggestions { list-style: none; margin: .5rem 0; padding: 0;
  display: flex; flex-direction: column; gap: .5rem; }
.cards .card { padding: 0; }
.cards .card a { display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: 1rem 1.2rem; text-decoration: none; color: var(--ink); }
.cards .t { font-weight: 600; }
.bal { font-size: .9rem; color: var(--muted); }
.bal.pos { color: var(--pos); }
.bal.neg { color: var(--neg); }

.bills li, .balances li, .suggestions li {
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .7rem .9rem;
}
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; letter-spacing: .02em; color: #fff;
  background: hsl(var(--avatar-hue, 210) 48% 42%); user-select: none; }
.avatars { flex: none; display: inline-flex; align-items: center; }
.avatars .avatar:not(:first-child) { margin-left: -10px; box-shadow: 0 0 0 2px var(--surface); }
.grow { flex: 1; min-width: 0; }
.bills .grow { display: flex; flex-direction: column; gap: .15rem; }
.bills li > a { flex: 1; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: .15rem; }
.bills .t { font-weight: 600; }
.bills .sub { font-size: .82rem; color: var(--muted); }
.bills .amt, .balances .amt { font-weight: 600; white-space: nowrap; }
.balances .who { flex: 1; }
.balances li.pos .amt { color: var(--pos); }
.balances li.neg .amt { color: var(--neg); }
.suggestions li { justify-content: space-between; }

.amt-big { font-size: 1.8rem; font-weight: 700; margin: .3rem 0; }

/* ---- bill participants + split preview ------------------------------ */
fieldset.participants { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; }
fieldset.participants legend { font-size: .8rem; color: var(--muted); padding: 0 .3rem; }
fieldset.participants label { padding: .25rem 0; }
.share { margin-left: auto; color: var(--accent); font-weight: 600; font-size: .9rem; }
label.cb { justify-content: flex-start; }
label.cb .share { margin-left: auto; }

/* ---- misc ----------------------------------------------------------- */
.flash { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius-sm);
  padding: .6rem .9rem; margin: 0 0 1rem; font-size: .92rem; }
.empty { color: var(--muted); padding: 1.5rem 0; }
.muted { color: var(--muted); font-size: .9rem; }
em { font-style: normal; color: var(--muted); font-size: .85em; }

/* ---- settle-up payment panel ---------------------------------------- */
/* The suggestion row keeps its single-line layout; the pay panel drops onto a
   full-width second line beneath it. */
.suggestions li { flex-wrap: wrap; }
.pay, .pay-none { flex-basis: 100%; }
.pay-none { margin: .2rem 0 0; }

.pay > summary {
  cursor: pointer; list-style: none; margin-top: .5rem;
  font-size: .9rem; font-weight: 600; color: var(--accent);
  padding: .3rem 0;
}
.pay > summary::-webkit-details-marker { display: none; }
.pay > summary::before { content: "▸ "; }
.pay[open] > summary::before { content: "▾ "; }

.pay-body {
  display: flex; flex-direction: column; gap: .9rem;
  padding: .8rem 0 .3rem;
  border-top: 1px solid var(--border); margin-top: .3rem;
}
.pay-qr { margin: 0; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
/* White plate behind the code: scanners need the light quiet zone even when the
   rest of the page is dark. */
.pay-qr img {
  width: min(280px, 100%); height: auto; display: block;
  background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.pay-qr figcaption { text-align: center; max-width: 34ch; }

.pay-fields { display: flex; flex-direction: column; gap: .4rem; }
.pay-field {
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: .45rem .6rem;
}
.pay-label { flex: none; width: 7.5rem; font-size: .78rem; color: var(--muted); }
.pay-value {
  flex: 1; min-width: 0; font-size: .9rem; word-break: break-all;
  user-select: all; /* one tap selects the whole IBAN */
}
.pay-field .copy { flex: none; padding: .3rem .6rem; font-size: .8rem; }
.pay-note { margin: 0; }

@media (max-width: 30rem) {
  .pay-field { flex-wrap: wrap; }
  .pay-label { width: 100%; }
}
