:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --ink: #15201e;
  --muted: #6b7a77;
  --line: #e4e8e6;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --warn: #b45309;
  --radius: 16px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --card: #17211f;
    --ink: #eaf1ef;
    --muted: #8fa19d;
    --line: #26332f;
    --brand: #2dd4bf;
    --brand-ink: #062a26;
    --danger: #f97066;
    --warn: #fbbf24;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-top: var(--safe-t);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + var(--safe-b) + 96px);
}
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }

/* Month switcher */
.month { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 18px; }
.month strong { font-size: 17px; }

/* Hero */
.hero { background: var(--brand); color: var(--brand-ink); border: 0; }
.hero .label { opacity: .85; font-size: 14px; }
.hero .total { font-size: 38px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; }
.hero .delta { font-size: 14px; opacity: .9; }

/* Donut + legend */
.donut { width: 132px; height: 132px; border-radius: 50%; flex: none; position: relative; }
.donut::after { content: ""; position: absolute; inset: 26px; border-radius: 50%; background: var(--card); }
.legend { display: flex; flex-direction: column; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.bar.budget { position: relative; height: 10px; }
.bar.budget .tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .55; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--brand); font: inherit; font-size: 13px; font-weight: 600; text-transform: none; letter-spacing: 0; }

/* Lists */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.item:last-child { border-bottom: 0; }
.ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 600; flex: none; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.day { font-size: 13px; color: var(--muted); margin: 18px 0 2px; display: flex; justify-content: space-between; }

/* Filters */
.filters { display: flex; gap: 8px; margin-bottom: 8px; }
.filters select { flex: 1; min-width: 0; }
select, input[type=text], input[type=number], input[type=date], input[type=search], input[type=email], textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
input[type=search] { -webkit-appearance: none; appearance: none; } /* plain box; keep native select/date widgets */
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 40px; }

/* Buttons */
.btn { padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; }

/* FAB + tabs */
/* Add button lives inside the tab bar so it never covers list content */
#tabs #fab {
  flex: none; align-self: flex-start; margin: 8px 16px 0 4px;
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--brand); color: var(--brand-ink); font-size: 32px; line-height: 1;
  display: grid; place-items: center; padding: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
#tabs button { flex: 1; min-width: 0; border: 0; background: none; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
#tabs button.active { color: var(--brand); font-weight: 600; }
#tabs button.active span { filter: none; opacity: 1; }

/* Bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-body {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-body h1 { margin-bottom: 8px; }
.field { margin: 14px 0; position: relative; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.amount-input { font-size: 34px !important; font-weight: 700; text-align: center; padding: 14px !important; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.chip.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); font-weight: 600; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat { padding: 10px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cat span { font-size: 22px; }
.cat.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 84px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Trends */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: 8px 16px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
svg.chart { width: 100%; height: auto; display: block; margin-top: 8px; touch-action: manipulation; }
svg.chart text { font-size: 9px; fill: var(--muted); font-family: inherit; }
svg.chart .grid line { stroke: var(--line); stroke-width: 1; }
svg.chart .avg { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 4 3; opacity: .55; }
svg.chart .avgt { fill: var(--ink); opacity: .7; }
svg.chart rect[data-m] { cursor: pointer; }
svg.spark { width: 84px; height: 26px; flex: none; }
svg.spark polyline { fill: none; stroke: var(--brand); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }

/* Category editor */
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 190px; overflow-y: auto; padding: 2px; }
.emoji-grid button { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 22px; padding: 0; }
.emoji-grid button.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatches button.on { box-shadow: 0 0 0 3px var(--ink); }

/* Description autocomplete */
.suggest { position: absolute; left: 0; right: 0; z-index: 10; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); overflow: hidden; }
.suggest[hidden] { display: none; }
.suggest button { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 11px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest button.on { background: color-mix(in srgb, var(--brand) 14%, var(--card)); }
.suggest b { font-weight: 700; }

/* About / DaCoders credit */
.about { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.about img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #fff; flex: none; } /* logo has a white square background: crop to its circle */

/* Duplicate warning */
.warn { margin: 12px 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--card)); }
.warn[hidden] { display: none; }

/* Sync status banner: only visible when something needs attention */
#syncbar { position: sticky; top: 0; z-index: 15; display: block; width: 100%; padding: 9px 16px; border: 0; border-bottom: 1px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 18%, var(--card)); color: var(--ink); font-size: 13px; font-weight: 600; text-align: center; }
#syncbar[hidden] { display: none; }

/* Slide-in when the month changes */
@keyframes fromLeft  { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@keyframes fromRight { from { opacity: 0; transform: translateX(28px); }  to { opacity: 1; transform: none; } }
#view.from-left  { animation: fromLeft .28s ease-out; }
#view.from-right { animation: fromRight .28s ease-out; }
@media (prefers-reduced-motion: reduce) { #view.from-left, #view.from-right { animation: none; } }

/* Add to Home Screen */
.install { margin: 4px 0 12px; gap: 12px; }
.install img { border-radius: 10px; flex: none; }
.install .linkbtn { padding: 8px; font-size: 16px; color: var(--muted); }
.steps { margin: 12px 0; padding-left: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.steps li:last-child { border-bottom: 0; }
.steps li::before { content: counter(step); flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 14px; }
