:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1c1916;
  --muted: #6f675e;
  --line: #e4ddd3;
  --accent: #8a4b2f;
  --good: #2f6b4f;
  --warn: #a15c12;
  --danger: #9b2c2c;
  --shadow: 0 1px 0 rgba(28, 25, 22, 0.06);
  font-family: "SF Pro Text", "PingFang SC", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161310;
    --surface: #211c18;
    --ink: #f4efe7;
    --muted: #b3aa9f;
    --line: #3a322b;
    --accent: #d08b6a;
    --good: #7dba98;
    --warn: #e0a45a;
    --danger: #e07a7a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { padding-bottom: 84px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.app-header h1 { margin: 0; font-size: 22px; }
.app-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.page { display: none; padding: 16px 20px 32px; }
.page.active { display: block; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
}
.segmented button.active { background: var(--ink); color: var(--bg); }

.hero, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.hero .label, .muted { color: var(--muted); font-size: 13px; }
.hero .amount { font-size: 36px; font-weight: 700; letter-spacing: -0.04em; margin: 6px 0; }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.list { display: flex; flex-direction: column; gap: 10px; }
.entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.entry:last-child { border-bottom: 0; }
.merchant { font-weight: 600; }
.meta { color: var(--muted); font-size: 12px; }
.money { font-variant-numeric: tabular-nums; }
.money.plus { color: var(--good); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 72px; gap: 8px; align-items: center; font-size: 13px; }
.bar {
  height: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar-row.tap, .row.tap, .entry.tap { cursor: pointer; }
.bar-row.tap:active, .row.tap:active, .entry.tap:active { opacity: 0.72; }
.period-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 16px;
}
.period-nav .period-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 12px;
  margin: 0 8px 12px 0;
}
.trend-row { font-size: 13px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.btn, .file-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
}
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.nav button.active { color: var(--accent); font-weight: 600; }
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-end;
  z-index: 10;
}
.sheet.open { display: flex; }
.sheet-body {
  background: var(--surface);
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.import-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.import-item .field { margin-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.progress {
  height: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0;
}
.progress > span { display: block; height: 100%; background: var(--accent); }
.hidden { display: none !important; }
.install-banner {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-size: 13px;
}
