:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1b1d1f;
  --muted: #6b7075;
  --line: #e4e0d8;
  --track: #ece8e0;
  --accent: #0f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ea;
  --danger: #b3382c;
  --danger-soft: #fbe9e6;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #1a1e1d;
    --ink: #eef0ee;
    --muted: #9aa19e;
    --line: #2a302e;
    --track: #272c2a;
    --accent: #4cc49a;
    --accent-ink: #06251b;
    --accent-soft: #17332a;
    --danger: #ff8a7a;
    --danger-soft: #3a1d19;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  text-align: inherit;
}

h1,
h2,
p {
  margin: 0;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.num {
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* ---------- header ---------- */

.top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.month {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--track);
  border-radius: 12px;
  padding: 3px;
}

.seg button {
  padding: 8px;
  border-radius: 9px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
}

.seg button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* ---------- cards and lists ---------- */

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

.card.flush {
  padding: 4px 0;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 20px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.section-title button {
  color: var(--accent);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
}

.summary .big {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.summary .label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 2px;
}

.summary .foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-size: 14px;
  margin-top: 10px;
}

.summary .foot > * {
  white-space: nowrap;
}

.bar {
  height: 8px;
  background: var(--track);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 12px;
}

.bar.thin {
  height: 6px;
  margin-top: 8px;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  min-width: 0;
}

.over {
  color: var(--danger);
}

.bar > i.over {
  background: var(--danger);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  min-height: 56px;
}

.row + .row {
  border-top: 1px solid var(--line);
}

.row .grow {
  flex: 1;
  min-width: 0;
}

.row .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .sub {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .amount {
  font-weight: 600;
  white-space: nowrap;
}

.cat-row {
  display: block;
  width: 100%;
  padding: 12px 16px;
}

.cat-row + .cat-row {
  border-top: 1px solid var(--line);
}

.cat-row .line {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.cat-row .name {
  flex: 1;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  align-self: center;
  background: var(--c, var(--muted));
}

.banner {
  background: var(--accent-soft);
  border-color: transparent;
}

.banner .section-title {
  margin: 0 0 4px;
  color: var(--accent);
}

.banner .row {
  padding-left: 0;
  padding-right: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

.day {
  margin: 16px 4px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- bottom nav ---------- */

nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

nav .inner {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

nav button svg {
  width: 24px;
  height: 24px;
}

nav button[aria-current='page'] {
  color: var(--accent);
}

nav button.add span.plus {
  width: 44px;
  height: 44px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ---------- sheet and forms ---------- */

dialog#sheet {
  margin: auto auto 0;
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow: auto;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--ink);
}

dialog#sheet::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.sheet-head h2 {
  font-size: 19px;
}

.sheet-head button {
  color: var(--muted);
  font-weight: 600;
  padding: 6px;
}

label.field {
  display: block;
  margin-bottom: 14px;
}

label.field > span,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type='text'],
input[type='date'],
select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  appearance: none;
  -webkit-appearance: none;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input.amount-input {
  font-size: 28px;
  font-weight: 700;
  min-height: 60px;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
  font-weight: 500;
}

.chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.swatches {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c);
}

.swatch[aria-pressed='true'] {
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c);
}

.btn {
  display: block;
  width: 100%;
  min-height: 50px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  text-align: center;
}

.btn.secondary {
  background: var(--track);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.6;
}

.btn + .btn {
  margin-top: 10px;
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin: 0 0 12px;
  min-height: 0;
}

/* ---------- setup, login, settings ---------- */

.hero {
  padding-top: 12vh;
}

.hero h1 {
  font-size: 30px;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.hero p.lead {
  color: var(--muted);
  margin-bottom: 24px;
}

.code-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.code-box code {
  font: 600 15px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
  min-width: 0;
}

.code-box button {
  color: var(--accent);
  font-weight: 600;
  flex: none;
}

ol.steps {
  margin: 0 0 16px;
  padding-left: 22px;
}

ol.steps li {
  margin-bottom: 10px;
}

table.kv {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 4px;
  font-size: 14px;
}

table.kv td {
  padding: 6px 8px;
  border: 1px solid var(--line);
}

table.kv td:first-child {
  font-weight: 600;
  width: 34%;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: calc(100% - 32px);
  z-index: 10;
}

#toast.show {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  #toast {
    transition: none;
  }
}
