:root {
  --bg: #f6f7f9; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #0f766e; --on-accent: #fff; --out: #b91c1c; --in: #15803d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --card: #151b23; --text: #e5e7eb; --muted: #9ca3af; --line: #263040;
    --accent: #2dd4bf; --on-accent: #042f2e; --out: #f87171; --in: #4ade80;
  }
}
* { box-sizing: border-box; }
html, body { background: var(--bg); }
body {
  margin: 0; color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

header {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
h1 { font-size: 18px; margin: 0; }
.pill { font-size: 13px; padding: 6px 12px; min-height: 32px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.pill[data-s="error"] { color: var(--out); }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(100px + env(safe-area-inset-bottom)); }

.month { display: flex; align-items: center; justify-content: space-between; }
.month h2 { font-size: 17px; margin: 0; }
.month button { width: 44px; height: 44px; font-size: 26px; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 8px; }
.totals div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.totals span { display: block; font-size: 12px; color: var(--muted); }
.totals strong { display: block; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.day h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 4px 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
}
.row + .row { border-top: 1px solid var(--line); }
.row div { min-width: 0; }
.row small { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--out); }
.amt.in { color: var(--in); }

#empty { text-align: center; color: var(--muted); margin-top: 32px; }
.link { display: block; margin: 24px auto 0; padding: 12px; color: var(--muted); text-decoration: underline; font-size: 14px; }

.fab {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom));
  right: max(16px, calc(50% - 320px + 16px));
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-size: 32px; line-height: 1;
  box-shadow: 0 4px 14px rgb(0 0 0 / .25);
}

/* Bottom sheet on phones, centered dialog on laptops. */
dialog {
  width: 100%; max-width: 100%; margin: auto 0 0; border: 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0; background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
@media (min-width: 640px) { dialog { max-width: 440px; margin: auto; border-radius: 16px; } }

form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
/* 16px stops iOS zooming into focused inputs. */
form input:not([type="radio"]), form select {
  display: block; width: 100%; margin-top: 4px; padding: 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 12px; background: var(--bg); border-radius: 10px; }
.seg label { position: relative; margin: 0; padding: 10px; text-align: center; border-radius: 8px; color: var(--text); font-size: 15px; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg label:has(input:checked) { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / .15); }
.seg label:has(:focus-visible) { outline: 2px solid var(--accent); }

.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions button { flex: 1; min-height: 48px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); }
.primary { background: var(--accent); color: var(--on-accent); border-color: transparent !important; font-weight: 600; }
.danger { color: var(--out); }
