:root {
  color-scheme: light;
  --ink: #111;
  --muted: #8c8c8c;
  --line: #ececec;
  --soft: #f5f5f5;
  --accent: #4c78a8;
  --pos: #2e9e5b;
  --neg: #d64545;
  --warn: #e8a23a;
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: #fff; overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0; font-weight: 700; }
h3 { font-size: 12px; margin: 26px 0 10px; color: var(--muted); font-weight: 400; text-transform: uppercase; letter-spacing: .07em; }

/* ---------- layout ---------- */
.top, main { max-width: 1120px; margin: 0 auto; padding-inline: 20px; }
.top { padding-top: calc(20px + env(safe-area-inset-top, 0px)); padding-bottom: 18px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.headline { padding-top: 18px; }
.hl-label { font-size: 13px; color: var(--muted); }
.hl-total { font-size: 44px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin: 2px 0 10px; }
.hl-bar { display: flex; gap: 2px; height: 6px; max-width: 420px; border-radius: 6px; overflow: hidden; background: var(--soft); }
.hl-sub { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.hl-sub span { display: inline-flex; align-items: center; gap: 6px; }
.hl-sub i { width: 8px; height: 8px; border-radius: 50%; }
@media (max-width: 480px) { .hl-total { font-size: 36px; } }
.month-nav { display: flex; align-items: center; gap: 2px; }
#monthLabel {
  font-weight: 700; font-size: 17px; min-width: 150px; text-align: center;
  background: none; border: 0; padding: 6px 8px; border-radius: 8px;
}
#monthLabel:hover { background: var(--soft); }
main { display: grid; gap: 16px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; min-height: 30px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 480px) {
  .top, main { padding-inline: 16px; }
  .card { padding: 16px; }
  #monthLabel { min-width: 0; font-size: 15px; }
  h1 { font-size: 19px; }
}

/* ---------- buttons ---------- */
button { cursor: pointer; touch-action: manipulation; }
.primary { background: var(--ink); color: #fff; border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 700; }
.ghost { background: var(--soft); border: 0; border-radius: 12px; padding: 10px 14px; }
.btn { display: inline-flex; align-items: center; cursor: pointer; }
.danger { background: #fff; color: var(--neg); border: 1px solid #f3caca; border-radius: 12px; padding: 9px 14px; }
.icon-btn {
  background: none; border: 0; width: 32px; height: 32px; border-radius: 8px; flex: none;
  font-size: 19px; line-height: 1; color: var(--muted); display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
button:focus-visible, input:focus-visible, label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 3px; justify-self: start; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 7px 16px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg.small button { padding: 5px 12px; font-size: 13px; }

/* ---------- inputs ---------- */
input:not([type=checkbox]):not([type=color]) {
  background: var(--soft); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; min-width: 0;
}
input:focus { outline: none; border-color: var(--ink); background: #fff; }
/* 16px or larger stops iPhones from zooming the page when you tap a field. */
input { font-size: 16px; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
input[type=color] { width: 34px; height: 34px; padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; flex: none; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 120px; }
.row > input[type=color] { flex: none; }

/* ---------- add form ---------- */
.add { display: grid; gap: 14px; }
.add.editing { border-color: var(--ink); }
#entryForm { display: grid; gap: 14px; }
.amount-row { display: flex; align-items: center; gap: 8px; }
.amount-row .cur { font-size: 34px; color: var(--muted); }
#amount {
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em;
  background: none; border: 0; padding: 0; flex: 1 1 auto; width: 0; min-width: 0;
}
.calc-result { font-size: 18px; color: var(--muted); white-space: nowrap; }
.calc-toggle {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); display: grid; place-items: center;
}
.calc-toggle:hover { color: var(--ink); }
.calc-toggle.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.calc-pad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; max-width: 340px; }
.calc-pad button { height: 46px; border: 0; border-radius: 12px; background: var(--soft); font-size: 18px; display: grid; place-items: center; }
@media (max-width: 480px) {
  #amount { font-size: 30px; }
  .amount-row .cur { font-size: 26px; }
  .calc-result { font-size: 15px; }
}
.calc-pad button:active { background: #e9e9e9; }
.calc-pad .op { background: #fff; border: 1px solid var(--line); font-weight: 700; }
.calc-pad .eq { background: var(--ink); color: #fff; font-weight: 700; }
#date { flex: 0 1 170px; }
#note { flex: 2 1 160px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-size: 14px;
}
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.on {
  border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c);
  background: #fff; background: color-mix(in srgb, var(--c) 14%, #fff);
}
.chip.add-chip { color: var(--muted); border-style: dashed; }

/* ---------- stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.tile .lbl { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.tile .lbl i { width: 8px; height: 8px; border-radius: 50%; }
.tile .val { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) { .tile .val { font-size: 21px; } }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.avgs { display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 14px 4px 0; }
.avgs div { display: flex; align-items: baseline; gap: 8px; }
.avgs span { color: var(--muted); font-size: 13px; }
.avgs b { font-size: 17px; }
.avgs small { color: var(--muted); font-size: 12px; }

/* ---------- budget ---------- */
.budget-top { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.budget-top b { font-size: 17px; }
.bar-track { position: relative; height: 12px; background: var(--soft); border-radius: 999px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--pos); transition: width .4s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.over { background: var(--neg); }
.pace { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 2px; }
.budget-foot { margin-top: 10px; color: var(--muted); font-size: 13px; }
.budget-empty { color: var(--muted); }

/* ---------- charts ---------- */
.chart { width: 100%; min-height: 220px; }
.chart svg, .pie-wrap svg { display: block; overflow: visible; }
svg text { font-family: inherit; }
.axis { font-size: 11px; fill: #a0a0a0; }
.axis.strong { fill: var(--ink); font-weight: 700; }
.gridline { stroke: var(--line); stroke-width: 1; }
.avg-line { stroke: var(--ink); stroke-dasharray: 4 4; stroke-width: 1; }
.avg-label { font-size: 11px; fill: var(--ink); font-weight: 700; }
.bar { cursor: pointer; }
.bar .hit { fill: transparent; }
.bar:hover .hit { fill: rgba(0, 0, 0, .03); }
.bar.active .hit { fill: rgba(0, 0, 0, .06); }
.empty-note { font-size: 13px; fill: var(--muted); }

.pie-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; }
.pie-wrap svg { flex: none; width: 180px; height: 180px; }
.slice { cursor: default; transition: opacity .15s; }
.slice:hover { opacity: .8; }
.pie-total { font-size: 20px; font-weight: 700; fill: var(--ink); }
.pie-sub { font-size: 11px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 180px; display: grid; gap: 10px; min-width: 0; }
.legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; font-size: 14px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; }
.legend .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .pct { color: var(--muted); font-size: 12px; margin-left: 4px; }
.legend .mini { grid-column: 2 / 4; height: 4px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.legend .mini span { display: block; height: 100%; border-radius: 4px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle.block { display: flex; margin-top: 10px; }
.toggle input { accent-color: var(--ink); margin: 0; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.day {
  position: relative; aspect-ratio: 1 / .88; border: 0; border-radius: 10px; background: var(--soft);
  padding: 6px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  text-align: left; min-width: 0; overflow: hidden;
}
.day .dn { font-size: 12px; }
.day .amt { font-size: 11px; font-weight: 700; align-self: stretch; text-align: right; white-space: nowrap; overflow: hidden; }
.day.dark { color: #fff; }
.day.today .dn { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.day.sel { box-shadow: 0 0 0 2px var(--ink); }
.day.future { opacity: .5; }
.day .fx { position: absolute; top: 7px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.day.dark .fx { background: #fff; }
.cal-legend { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.heat { display: inline-block; width: 80px; height: 8px; border-radius: 4px; vertical-align: middle; margin: 0 6px; background: linear-gradient(90deg, rgba(46, 158, 91, .12), rgb(46, 158, 91)); }

.cal-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.cs { background: var(--soft); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.cs .lbl, .cs .val, .cs .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs .lbl { font-size: 12px; color: var(--muted); }
.cs .val { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 7px; }
.cs-bar { display: flex; gap: 1px; height: 4px; border-radius: 4px; overflow: hidden; background: #e4e4e4; }
.cs .sub { font-size: 11px; color: var(--muted); margin-top: 6px; }
@media (max-width: 480px) {
  .cal-summary { gap: 6px; }
  .cs { padding: 8px 9px; }
  .cs .val { font-size: 15px; }
}
.fx-key { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); margin-right: 6px; vertical-align: middle; }
@media (max-width: 480px) {
  .cal { gap: 3px; }
  .day { padding: 4px; border-radius: 7px; }
  .day .amt { font-size: 9.5px; text-align: center; }
  .day .fx { top: 5px; right: 5px; width: 5px; height: 5px; }
}

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.li-main b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-main small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .amt { font-weight: 700; white-space: nowrap; }
.list li.empty { color: var(--muted); justify-content: center; padding: 24px 0; border: 0; text-align: center; }
.list li.fixed-row { color: var(--muted); }
.list .acts { display: flex; flex: none; }
#fixedForm { margin-top: 14px; }
#fixedForm #fxDay { flex: 0 1 100px; }
.day-total { font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- settings dialog ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; color: var(--ink); background: #fff;
  width: min(560px, calc(100vw - 32px)); max-height: 86vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .25); }
.dlg { padding: 24px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { font-size: 19px; }
#catEdit li { gap: 10px; padding: 5px 0; border: 0; }
#catEdit input[data-k=name] { flex: 1; }
.count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dlg p.muted { margin: 0 0 12px; }

/* ---------- sync ---------- */
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c4c4c4; margin-right: 8px; vertical-align: 1px; flex: none; }
.sync-dot.synced { background: var(--pos); }
.sync-dot.syncing { background: var(--warn); }
.sync-dot.error { background: var(--neg); }
.sync-status { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sync-status .sync-dot { margin: 0; }
.full { flex-basis: 100%; margin: 0 0 2px; }
#syncSignIn .link { margin-right: 16px; font-size: 13px; }
#syncSignIn .full:last-child { margin-top: 4px; }

/* ---------- tooltip & toast ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: #fff;
  border-radius: 10px; padding: 9px 11px; font-size: 12px; min-width: 130px; max-width: 240px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.tooltip b { display: block; font-weight: 400; opacity: .75; }
.tt-total { display: block; font-size: 16px; font-weight: 700; margin: 2px 0 4px; }
.tt-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.tt-row i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tt-row span { margin-left: auto; padding-left: 12px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: #fff; border-radius: 999px; padding: 10px 18px;
  display: flex; gap: 14px; align-items: center; font-size: 14px; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); max-width: calc(100vw - 32px);
}
.toast.has-undo { padding-right: 8px; }
.toast button { background: #fff; color: var(--ink); border: 0; border-radius: 999px; padding: 6px 13px; font-weight: 700; }
