:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201b;
  --muted: #6b7570;
  --line: #e3e8e5;
  --accent: #1f7a4d;
  --accent-soft: #d6ece0;
  --neg: #b23a3a;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --info-bg: #e3f0ff;
  --info-text: #1d4370;
  --err-bg: #fde4e4;
  --err-text: #7a1f1f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --card: #19201c;
    --text: #e6ece8;
    --muted: #93a099;
    --line: #2a332e;
    --accent: #3fae78;
    --accent-soft: #1f3a2c;
    --neg: #ef7b7b;
    --warn-bg: #3a3014;
    --warn-text: #f2d68a;
    --info-bg: #15283d;
    --info-text: #a9cbf2;
    --err-bg: #3d1818;
    --err-text: #f5b3b3;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
}
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; text-align: center; flex: 1; }
h2 { font-size: 1rem; margin: 0 0 12px; }
small { font-size: 0.8rem; }
.muted { color: var(--muted); }
.neg { color: var(--neg); }

.top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.nav {
  width: 44px; height: 44px; display: grid; place-items: center;
  font-size: 1.8rem; text-decoration: none; border-radius: 12px;
}
.nav.off { opacity: 0.25; }

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.hero, .saved { text-align: center; }
.saved-head { margin-bottom: 10px; }
.big-num { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn-big { width: 100%; padding: 18px; font-size: 1.15rem; border-radius: 16px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 0; cursor: pointer; }

.upload { margin-bottom: 12px; }
.who { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.who-label { font-size: 0.9rem; margin-right: 2px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); font-size: 0.95rem;
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.upload.busy .who { display: none; }
.people { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.person {
  flex: 1 1 30%; background: var(--accent-soft); border-radius: 12px; padding: 8px;
  display: flex; flex-direction: column; min-width: 0;
}
.person span { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.person small { color: var(--muted); }
.busy-msg { display: none; text-align: center; padding: 18px; color: var(--muted); }
.upload.busy label { display: none; }
.upload.busy .busy-msg { display: block; }
.spinner {
  display: inline-block; width: 16px; height: 16px; vertical-align: -3px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar-row { margin-bottom: 10px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 0.95rem; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.top-items { list-style: none; margin: 0; padding: 0; }
.top-items li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.top-items li + li { border-top: 1px solid var(--line); }

.receipts { list-style: none; margin: 0; padding: 0; }
.receipts li { display: flex; align-items: center; gap: 4px; }
.receipts li + li { border-top: 1px solid var(--line); }
.rec-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 0; color: inherit; text-decoration: none; }
.receipts .what { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thumb {
  width: 44px; height: 58px; flex: none; object-fit: cover; object-position: top;
  border-radius: 6px; background: var(--line);
}
.thumb-pdf { display: grid; place-items: center; font-size: 0.7rem; font-weight: 700; color: var(--muted); }

.del-form { margin: 0; }
.icon-btn {
  min-width: 44px; height: 44px; padding: 0 8px; border: 0; border-radius: 10px;
  background: none; font: inherit; font-size: 1.1rem; cursor: pointer; color: var(--text);
}
.icon-btn.armed { background: var(--neg); color: #fff; font-size: 0.85rem; font-weight: 600; }
.btn-danger.armed { filter: brightness(0.85); }
.del-row { padding-top: 12px; }
.del-row .btn { width: 100%; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; }
.hint { font-size: 0.8rem; margin: 12px 0 4px; }
.items { margin-top: 4px; }
.item { border-top: 1px solid var(--line); }
.item summary {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 10px 0; font-weight: 400; list-style: none;
}
.item summary::-webkit-details-marker { display: none; }
.item[open] summary { font-weight: 600; }
.item-name { display: flex; flex-direction: column; min-width: 0; }
.item-name small { font-weight: 400; }
.item-add summary { color: var(--accent); font-weight: 600; }
.item-form { background: var(--bg); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
.item-form input { background: var(--card); }
.item .del-form { margin-bottom: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.btn-block { width: 100%; }
.btn-small { padding: 8px 12px; font-size: 0.9rem; margin-top: 8px; }
.inline-form { margin: 0; }

summary { padding: 4px 0 12px; cursor: pointer; font-weight: 600; }
.bon-img { width: 100%; border-radius: 8px; display: block; margin-bottom: 6px; }

.stack { display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}

.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 0.95rem; }
.flash-error { background: var(--err-bg); color: var(--err-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }
.flash-warn { background: var(--warn-bg); color: var(--warn-text); margin-top: 12px; }

.empty { text-align: center; padding: 24px 0; }
.foot { display: flex; justify-content: center; margin-top: 20px; font-size: 0.9rem; }

.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login-icon { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { margin: 12px 0 20px; }
.login .card { text-align: left; }
