:root {
  color-scheme: light dark;
  --bg: #f6f3ed;
  --surface: #ffffff;
  --surface-2: #efeae1;
  --text: #1f1d1a;
  --muted: #6d665c;
  --border: #e2dacd;
  --primary: #2f5d50;
  --primary-ink: #ffffff;
  --primary-soft: #e1ede8;
  --pos: #2e7a4f;
  --neg: #b4432e;
  --neg-soft: #f8e6e1;
  --warn-soft: #fbf1d9;
  --request: #9a4a26;
  --request-soft: #f6e7dc;
  --radius: 14px;
  --nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211;
    --surface: #1d1b19;
    --surface-2: #272421;
    --text: #ede8e0;
    --muted: #a69f94;
    --border: #35312c;
    --primary: #8cc7b1;
    --primary-ink: #0f241d;
    --primary-soft: #1f332c;
    --pos: #7fcf9f;
    --neg: #f08f78;
    --neg-soft: #3a221c;
    --warn-soft: #3a321d;
    --request: #f0b08a;
    --request-soft: #3b2a20;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

a { color: var(--primary); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
h1:focus { outline: none; }
p { margin: 0; }

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding: 20px 16px calc(var(--nav-height) + 32px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}

.stack { display: grid; gap: 12px; }
.center { justify-items: center; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--neg); }
.error:empty { display: none; }
.notice { background: var(--warn-soft); padding: 10px 14px; border-radius: var(--radius); }
.warning { background: var(--neg-soft); padding: 12px 14px; border-radius: var(--radius); }
.loading { text-align: center; color: var(--muted); padding: 48px 0; }
.offscreen { position: absolute; left: -9999px; }

/* buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button.danger { color: var(--neg); background: transparent; margin-top: 24px; }
.button:disabled { opacity: 0.55; cursor: progress; }
.button:focus-visible, .action:focus-visible, .tab:focus-visible, .listing:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.center .button { width: 100%; }
.back { justify-self: start; color: var(--muted); text-decoration: none; padding: 8px 0; }
.back::before { content: "‹ "; }

/* forms */
.field { display: grid; gap: 6px; }
label, legend { font-weight: 600; }
input, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { resize: vertical; }
fieldset.choices { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
fieldset.choices legend { margin-bottom: 6px; }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 500;
}
.choice input { width: auto; margin: 0; accent-color: var(--primary); }
.amount-input { display: flex; align-items: center; gap: 10px; }
.amount-input input { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

/* cards and numbers */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 6px;
}
.label { color: var(--muted); font-size: 0.9rem; }
.name { font-weight: 700; font-size: 1.15rem; }
.amount { font-size: 2.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.amount .unit { font-size: 1rem; font-weight: 500; color: var(--muted); margin-left: 8px; }
.amount.neg, .delta.neg { color: var(--neg); }
.amount.pos, .delta.pos { color: var(--pos); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0 0; }
.facts dt { color: var(--muted); font-size: 0.85rem; }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.balance .hint { margin-top: 6px; }
.greeting { font-size: 1.3rem; }

/* home actions */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action {
  display: grid;
  justify-items: start;
  gap: 2px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-ink);
  text-decoration: none;
}
.action .icon { width: 28px; height: 28px; margin-bottom: 6px; }
.action-label { font-weight: 700; font-size: 1.15rem; }
.action-hint { font-size: 0.85rem; opacity: 0.85; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list > li.empty, .list > li.error { padding: 8px 0; }
.exchange {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.exchange a { color: var(--text); font-weight: 600; text-decoration: none; }
.meta { color: var(--muted); font-size: 0.85rem; }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.more { justify-self: start; }

.listing {
  display: grid;
  gap: 4px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.listing-title { font-weight: 700; font-size: 1.05rem; }
.price { font-weight: 600; color: var(--primary); }
.price.big { font-size: 1.2rem; }
.description { white-space: pre-wrap; }
.badge {
  justify-self: start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.request { background: var(--request-soft); color: var(--request); }

.toolbar { display: flex; gap: 10px; }
.toolbar input { flex: 1; min-width: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tab {
  min-height: 40px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.tab[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }

/* QR codes and scanner */
.qr { width: min(100%, 300px); padding: 12px; background: #ffffff; border-radius: var(--radius); border: 1px solid var(--border); }
.qr svg { display: block; width: 100%; height: auto; }
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000000; aspect-ratio: 1; }
.scanner-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, 0.85); border-radius: 18px; }
.code-box {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 10px;
  user-select: all;
  text-align: left;
  width: 100%;
}
.status { color: var(--muted); }
.payee { font-size: 1.15rem; font-weight: 600; }
.success { width: 100%; }
.success .icon { width: 64px; height: 64px; padding: 14px; border-radius: 50%; background: var(--primary-soft); color: var(--pos); stroke-width: 2.5; }

/* welcome */
.welcome { text-align: center; justify-items: center; padding-top: 12vh; }
.welcome .stack { width: 100%; margin-top: 12px; }
.logo { border-radius: 18px; }
.tagline { font-size: 1.2rem; font-weight: 600; color: var(--primary); }

/* chrome */
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav[hidden] { display: none; }
.nav a {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: var(--nav-height);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
}
.nav a[aria-current="page"] { color: var(--primary); font-weight: 700; }

.offline { position: sticky; top: 0; z-index: 20; background: var(--warn-soft); text-align: center; padding: 8px 16px; font-size: 0.9rem; }
.offline[hidden] { display: none; }

.toasts {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-height) + 16px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  justify-items: center;
  z-index: 30;
  pointer-events: none;
}
.toast { max-width: 30rem; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; }
.toast.error { background: var(--neg); color: #ffffff; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }
.center .row { justify-content: center; }
.home-top { display: grid; gap: 14px; }
.scanner-video.mirrored { transform: scaleX(-1); }
/* .nav a would show it: the brand belongs to the sidebar only. */
.nav .nav-brand { display: none; }
.action, .listing { cursor: pointer; }

@media (hover: hover) {
  .button:hover:not(:disabled) { filter: brightness(0.96); }
  .button.primary:hover:not(:disabled), .action:hover { filter: brightness(1.08); }
  .listing:hover, .exchange:hover { border-color: var(--primary); }
  .tab:hover { border-color: var(--primary); }
}

/* computer screens: sidebar instead of the bottom bar, wider pages */
@media (min-width: 900px) {
  :root { --sidebar: 240px; }

  .nav {
    top: 0;
    right: auto;
    width: var(--sidebar);
    grid-template-columns: none;
    grid-auto-rows: min-content;
    align-content: start;
    gap: 4px;
    padding: 20px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .nav a {
    grid-template-columns: 24px 1fr;
    justify-items: start;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 1rem;
  }
  .nav a[aria-current="page"] { background: var(--primary-soft); }
  .nav .nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 700;
  }
  .nav-brand img { border-radius: 8px; }

  body.with-nav #app, body.with-nav .offline { margin-left: var(--sidebar); }

  .page { padding: 40px 32px 48px; }
  .page.wide { max-width: 60rem; }

  .home-top { grid-template-columns: 3fr 2fr; align-items: stretch; }
  .home-top .actions { grid-template-columns: 1fr; }
  .home-top .action { align-content: center; }

  .list.cards { grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
  .list.cards > li.empty, .list.cards > li.error { grid-column: 1 / -1; }
  .listing { height: 100%; align-content: start; }

  .toasts { left: auto; right: 24px; bottom: 24px; justify-items: end; }
}

/* committee: requests to join */
.request h2 { margin: 0; }
.details { display: grid; gap: 8px; margin: 4px 0 0; }
.details dt { color: var(--muted); font-size: 0.85rem; }
.details dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
