:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #14211f;
  --muted: #5f6f6b;
  --line: #e2e8e6;
  --brand: #0f3d3a;
  --accent: #14b8a6;
  --accent-ink: #0b7d71;
  --gold: #d99a1e;
  --in: #11865b;
  --out: #14211f;
  --warn: #b45309;
  --bad: #c2362f;
  --chip: #eef3f1;
  --shadow: 0 1px 2px rgba(15, 61, 58, .06), 0 4px 16px rgba(15, 61, 58, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1514;
    --card: #13201e;
    --ink: #e7efed;
    --muted: #93a6a1;
    --line: #22332f;
    --brand: #0f3d3a;
    --accent: #2dd4bf;
    --accent-ink: #5eead4;
    --gold: #f6c453;
    --in: #4ade80;
    --out: #e7efed;
    --warn: #fbbf24;
    --bad: #f87171;
    --chip: #1b2b28;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand img { border-radius: 7px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; width: 36px; height: 36px; border-radius: 10px; font-size: 18px; }
.cur-toggle { background: rgba(255,255,255,.12); border: 0; color: #fff; height: 36px; padding: 0 12px; border-radius: 10px; font-weight: 600; font-size: 13px; }
#view { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(100px + env(safe-area-inset-bottom)); }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent-ink); font-weight: 600; }
.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 11; width: 58px; height: 58px;
  border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgba(20, 184, 166, .45);
}
@media (prefers-color-scheme: dark) { .fab { color: #062b27; } }
@media (min-width: 800px) { .fab { right: calc(50% - 360px); } }

/* ---------- cards & text */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 0 0 14px; border: 1px solid var(--line); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
h2 .link { text-transform: none; letter-spacing: 0; }
h3 { margin: 0 0 6px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.link { background: none; border: 0; color: var(--accent-ink); padding: 0; font-weight: 600; }
.in { color: var(--in); }
.neg { color: var(--bad); }
.warn { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; }

.hero { background: linear-gradient(135deg, #0f3d3a, #155e57); color: #fff; border: 0; padding: 18px 18px 16px; }
.hero .label { opacity: .8; font-size: 13px; }
.hero .big { font-size: 38px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 4px; }
.hero .big.neg { color: #fecaca; }
.hero .sub { font-size: 13px; opacity: .85; }
.hero .link { color: #99f6e4; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 12px; color: var(--muted); }

/* ---------- entry rows */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.day { padding: 8px 14px 4px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--chip); }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.list > .row:first-child, .day + .row { border-top: 0; }
.row:active { background: var(--chip); }
.check { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: transparent; display: grid; place-items: center; padding: 0; color: transparent; font-size: 14px; }
.row.paid .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.row.skipped { opacity: .45; }
.row.skipped .name { text-decoration: line-through; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; flex: none; }
.row .amt .a { font-weight: 600; }
.row .amt .b { font-size: 12px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--chip); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.tag.eur { background: #fef3c7; color: #92400e; }
@media (prefers-color-scheme: dark) { .tag.eur { background: #3b2f12; color: #fcd34d; } }
.row .acts { display: flex; gap: 6px; flex: none; }
.pill { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 600; }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .pill.primary { color: #062b27; } }

/* ---------- plan periods */
.period-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 12px 14px; background: var(--chip); }
.period-head .t { font-weight: 700; }
.period.current { outline: 2px solid var(--accent); outline-offset: -1px; }
.period .sum { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 2px; flex-wrap: wrap; }
.period .endbal { text-align: right; }
.period .endbal .v { font-weight: 700; font-size: 17px; }
.more { display: flex; justify-content: center; margin: 4px 0 14px; }

/* ---------- bars */
.bar { height: 8px; border-radius: 6px; background: var(--chip); overflow: hidden; position: relative; margin-top: 6px; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.bar > span.planned { opacity: .4; }
.budget-row { padding: 10px 14px; border-top: 1px solid var(--line); }
.budget-row:first-child { border-top: 0; }
.budget-row .top-line { display: flex; justify-content: space-between; gap: 8px; }
.trend { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 6px 2px 0; }
.trend .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.trend .cols { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.trend .cols span { width: 42%; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .lbl { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthnav .t { font-weight: 700; font-size: 18px; }
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.out button.on[data-v="out"] { color: var(--bad); }
.seg.in button.on[data-v="in"] { color: var(--in); }

/* ---------- forms & sheet */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea, input:not([type]) {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.amount-input { font-size: 28px !important; font-weight: 700; text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px; font-weight: 700; background: var(--accent); color: #fff; min-height: 46px; }
@media (prefers-color-scheme: dark) { .btn { color: #062b27; } }
.btn.secondary { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn + .btn { margin-top: 8px; }
.btn:disabled { opacity: .6; }
.checkline { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }
.err { color: var(--bad); font-size: 13px; margin: -4px 0 10px; min-height: 1em; }
.sheet-wrap { position: fixed; inset: 0; background: rgba(5, 20, 18, .45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .18s ease-out;
}
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); } to { transform: none; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.x { background: var(--chip); border: 0; width: 32px; height: 32px; border-radius: 50%; font-size: 18px; color: var(--muted); }
.info { background: var(--chip); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; color: var(--muted); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); background: #102624; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 40; max-width: 90vw; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: #7f1d1d; }

/* ---------- login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; }
.login h1 { margin: 12px 0 2px; font-size: 30px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.login form { text-align: left; }
body.signed-out .topbar { display: none; }

/* ---------- settings lists */
.setrow { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.list > .setrow:first-child { border-top: 0; }
.setrow .main { flex: 1; min-width: 0; }
.setrow .chev { color: var(--muted); }
.import-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.import-table td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.import-table input[type=text] { min-height: 34px; padding: 6px 8px; }
input[type=color] { width: 44px; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--card); }
.search { margin-bottom: 10px; }

/* ---------- calendar */
:root { --co: #d9622b; --period: rgba(20, 184, 166, .13); }
@media (prefers-color-scheme: dark) { :root { --co: #fb923c; --period: rgba(45, 212, 191, .14); } }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-head .pill { font-size: 20px; line-height: 1; padding: 6px 14px; }
.cal-title { text-align: center; min-width: 0; }
.cal-title .t { font-weight: 700; font-size: 16px; }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats.three .s:empty { display: none; }
.stats.three .v { font-size: 17px; }
.card.chart { padding: 10px 12px 8px; }
.card.cal { padding: 10px 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.cal-day {
  min-height: 52px; border: 1px solid transparent; border-radius: 9px; background: var(--chip); padding: 3px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--ink); min-width: 0;
}
.cal-day.blank { background: transparent; min-height: 0; }
.cal-day.past { background: transparent; border-color: var(--line); }
.legend s { color: var(--co); }
.cal-day .dn { font-weight: 600; white-space: nowrap; }
.cal-day .ci { color: var(--in); font-weight: 600; }
.cal-day .co { color: var(--co); font-weight: 600; }
.cal-day.today .dn { background: var(--accent); color: #fff; border-radius: 6px; padding: 0 4px; }
.cal-day.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; opacity: 1; }
.cal-day.done .co { text-decoration: line-through; opacity: .7; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--chip); margin: 2px 0 10px; }
.stack span { height: 100%; }
.stack span.left { background: repeating-linear-gradient(45deg, var(--in) 0 4px, transparent 4px 8px); opacity: .5; }
.cat-line { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cat-line:first-of-type { border-top: 0; }
h2 .link { margin-left: auto; }

/* ---------- accounts and bank */
.acct-ico { flex: none; width: 32px; height: 32px; border-radius: 10px; background: var(--chip); display: grid; place-items: center; font-weight: 700; color: var(--accent-ink); }
.review-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: inherit; text-decoration: none; border-color: var(--gold); }
.warn-box { color: var(--warn); }
.steps { margin: 0 0 12px; padding-left: 18px; }
.steps li { margin-bottom: 4px; }
textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); font-family: ui-monospace, Consolas, monospace; font-size: 13px; resize: vertical; }
