:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #1a1a18;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --accent: #2f6f4f;
  --warn: #a4501b;
  --alert: #9b2c2c;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --card: #1f2225;
    --ink: #ecebe6;
    --muted: #9a9a94;
    --line: #2e3236;
    --accent: #6cc39a;
    --warn: #e0a06a;
    --alert: #e88b8b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

h1 { font-size: 1.1rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.95rem; margin: 0 0 10px; color: var(--muted); font-weight: 600; }

nav {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 53px;
  background: var(--bg);
  z-index: 4;
}

nav button {
  flex: 1 0 auto;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

nav button.active {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 600;
}

main { padding: 14px 12px 60px; max-width: 820px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row:first-child { padding-top: 0; }

.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 0.85rem; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }

.big { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.pill.paid { color: var(--warn); border-color: currentColor; }
.pill.filed { color: var(--accent); border-color: currentColor; }
.pill.reimbursed { color: var(--muted); }
.pill.denied, .pill.overdue { color: var(--alert); border-color: currentColor; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 9px 14px;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.sm { padding: 5px 10px; font-size: 0.82rem; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.bar { height: 7px; border-radius: 4px; background: var(--accent); opacity: 0.85; min-width: 3px; }
.bar-wrap { display: flex; align-items: center; gap: 10px; }
.bar-track { flex: 1; }

.gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
}

.gate button { padding: 12px 26px; font-weight: 600; background: var(--accent); border-color: var(--accent); color: #fff; }
.gate p { color: var(--muted); margin: 0; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.sheet-inner {
  background: var(--bg);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px 28px;
}

@media (min-width: 640px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-inner { max-width: 520px; border-radius: 18px; }
}

.close { float: right; }

label { display: block; font-size: 0.82rem; color: var(--muted); margin: 12px 0 4px; }

input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 30;
  max-width: 90vw;
}

.empty { color: var(--muted); font-size: 0.9rem; }
button.active-filter { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.cal-embed { width: 100%; height: 60vh; min-height: 380px; border: 1px solid var(--line); border-radius: 10px; }
img.receipt { width: 100%; border-radius: 10px; border: 1px solid var(--line); margin-top: 10px; }
.tabular { font-variant-numeric: tabular-nums; }
