:root {
  --bg: #e6e0d4;
  --ink: #1c1915;
  --muted: #7c746a;
  --faint: #a39b91;
  --line: rgba(28, 25, 21, 0.1);
  --paper: rgba(255, 252, 247, 0.78);
  --accent: #1e6a4f;
  --accent-soft: #e4f0ea;
  --warn: #8a5a12;
  --warn-soft: #f6edd9;
  --danger: #8d3d32;
  --serif: "New York", "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.modal-open { overflow: hidden; }
body {
  background:
    radial-gradient(900px 420px at 50% -80px, #f8f3ea 0%, transparent 60%),
    var(--bg);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
button, a { -webkit-tap-highlight-color: transparent; }

#app { min-height: 100vh; }
.wrap {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 28px 20px calc(48px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
}
.ghost {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;
}
.month {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month strong {
  min-width: 148px;
  text-align: center;
  font-weight: 560;
}
.icon-btn, .primary, .line-btn {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  min-height: 40px;
}
.icon-btn {
  width: 40px;
  padding: 0;
}
.icon-btn:disabled { opacity: 0.35; }
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  background: var(--ink);
  color: #f7f3ec;
  border-color: var(--ink);
  text-decoration: none;
}
.line-btn { padding: 0 14px; background: transparent; }

.total {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(52px, 10vw, 84px);
  letter-spacing: -0.04em;
  line-height: 0.92;
}
.totals {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 28px;
  margin: 22px 0 6px;
}
.currency-unit {
  font-family: var(--sans);
  font-size: 0.34em;
  font-weight: 560;
  letter-spacing: 0;
  margin-left: 0.16em;
  vertical-align: 0.7em;
}
.sub { margin: 0; color: var(--muted); }
.review {
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--warn-soft);
  color: var(--warn);
  text-align: left;
  width: 100%;
}
.review.on {
  background: var(--ink);
  color: #f7f3ec;
}

.pills, .cats { display: flex; gap: 8px; margin-top: 22px; }
.pills { overflow-x: auto; padding-bottom: 2px; }
.pill, .cat {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  white-space: nowrap;
}
.pill.on, .cat.on { background: var(--ink); color: #f6f1e8; }
.cats { flex-direction: column; gap: 2px; margin-top: 8px; }
.cat {
  display: grid;
  grid-template-columns: 116px 1fr auto;
  gap: 12px;
  align-items: center;
  border-radius: 12px;
  text-align: left;
  padding: 9px 10px;
}
.cat b { font-weight: 560; color: var(--ink); }
.cat.on b, .cat.on { color: #f6f1e8; }
.bar {
  height: 3px;
  border-radius: 99px;
  background: rgba(28, 25, 21, 0.08);
  overflow: hidden;
}
.bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.cat.on .bar { background: rgba(255,255,255,0.2); }
.cat.on .bar i { background: #f6f1e8; }

.day { margin-top: 28px; }
.day h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 560;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}
.row {
  width: 100%;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  border-radius: 0;
}
.row:hover { background: rgba(255, 252, 247, 0.45); }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-style: normal;
  background: var(--clay, #d9cfc2);
}
.who strong, .who em { display: block; }
.who em { color: var(--muted); font-style: normal; font-size: 13px; margin-top: 2px; }
.money { font-variant-numeric: tabular-nums; font-weight: 560; }
.warn-dot { color: var(--warn); }

.empty {
  margin-top: 36px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.03em;
}

.more { margin-top: 36px; color: var(--muted); }
.more summary { cursor: pointer; }
.add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.add input, .sheet input, .sheet select, .sheet textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdfb;
  border-radius: 12px;
  padding: 12px 12px;
  outline: none;
}
.add input { flex: 1; }
.sheet textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #b7cfc4; }

.login {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: start;
  width: min(460px, calc(100% - 40px));
  margin: 0 auto;
}
.login h1 { font-size: 64px; }
.lead { font-size: 18px; line-height: 1.45; color: var(--ink); max-width: 28ch; }
.login .primary { margin-top: 8px; min-height: 48px; }
.hint { color: var(--danger); }

.loading {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}
.loading p { margin: 0; }
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(28, 25, 21, 0.12);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fffaf3;
  background: #332e28;
  box-shadow: 0 10px 30px rgba(40, 32, 24, 0.22);
  text-align: center;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 24, 0.28);
  display: grid;
  align-items: end;
  justify-items: center;
}
.sheet {
  width: min(560px, 100%);
  max-height: min(92vh, 820px);
  overflow: auto;
  background: #fbf7f1;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(40, 32, 24, 0.16);
}
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h3 { margin: 8px 0 16px; font-family: var(--serif); font-size: 32px; font-weight: 500; }
.fields { display: grid; gap: 10px; }
.fields label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.receipt {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 16px;
  margin: 4px 0 12px;
  background: #fff;
  cursor: zoom-in;
}
.receipt.expanded {
  max-height: none;
  cursor: zoom-out;
}
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions .primary, .actions .line-btn { flex: 1; min-height: 46px; }
.danger { color: var(--danger); border-color: transparent; background: transparent; }

@media (max-width: 480px) {
  .wrap { padding: 22px 15px calc(40px + env(safe-area-inset-bottom)); }
  h1 { font-size: 36px; }
  .month { margin-top: 2px; }
  .month strong { min-width: 126px; font-size: 14px; }
  .totals { margin-top: 20px; }
  .total { font-size: clamp(50px, 16vw, 70px); }
  .cat { grid-template-columns: 92px 1fr auto; gap: 9px; padding-inline: 8px; }
  .row { grid-template-columns: 34px minmax(0, 1fr) auto; gap: 9px; padding-inline: 6px; }
  .avatar { width: 34px; height: 34px; }
  .who { min-width: 0; }
  .who strong, .who em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .money { font-size: 14px; }
  .sheet { max-height: 94dvh; }
}

@media (min-width: 800px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 22px; padding: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spinner { animation: none; }
}
