:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1a2421;
  --muted: #64716d;
  --border: #dde3e1;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --danger: #b42318;
  --bar-track: #e8eceb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #182120;
    --text: #e6ecea;
    --muted: #93a19d;
    --border: #2a3533;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --danger: #f97066;
    --bar-track: #24302e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; text-align: center; font-size: 1.1rem; margin: 0; font-weight: 600; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.settings-btn { font-size: 1.1rem; }

main { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: .95rem; margin: 0 0 12px; color: var(--muted); font-weight: 600; }

.summary { text-align: center; }
.summary-label { color: var(--muted); font-size: .9rem; }
.summary-total { font-size: 2.4rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary-sub { color: var(--muted); font-size: .85rem; }

/* category breakdown */
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin-bottom: 12px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-name { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.cat-amt { font-variant-numeric: tabular-nums; font-size: .95rem; }
.cat-amt small { color: var(--muted); margin-left: 6px; }
.bar { grid-column: 1 / -1; height: 8px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* list */
.day-head {
  display: flex; justify-content: space-between;
  font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  margin: 14px 0 4px;
}
.day-head:first-child { margin-top: 0; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 4px; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 1.1rem;
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 500; }
.item-note { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-text);
  font-size: 2rem; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* dialogs */
dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text); padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 16px; font-size: 1.15rem; }
dialog h3 { margin: 20px 0 4px; font-size: 1rem; }
dialog label { display: block; margin-bottom: 14px; font-size: .9rem; color: var(--muted); }
dialog input, dialog select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
dialog input:focus, dialog select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.spacer { flex: 1; }
.stack { display: grid; gap: 8px; }

.btn {
  padding: 10px 16px; border-radius: 10px; font: inherit; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
label.btn.file-btn { margin: 0; color: var(--text); font-size: .95rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; margin: 0 0 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; transition: .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
