:root {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242423;
  --surface-3: #2e2e2c;
  --hair: #2c2c2a;
  --axis: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --blue: #3987e5;
  --orange: #d95926;
  --aqua: #199e70;
  --yellow: #c98500;
  --violet: #9085e9;
  --good: #0ca30c;
  --bad: #e66767;
  --warn: #fab219;
  --c-ESSENCIAL: var(--blue);
  --c-COMODITAT: var(--orange);
  --c-FORMIGA: var(--aqua);
  --c-FUTUR: var(--yellow);
  --c-liquid: var(--blue);
  --c-savings: var(--aqua);
  --c-invest: var(--violet);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --r: 18px;
  --tabs-h: 58px;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
html, body { margin: 0; height: 100%; background: var(--plane); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); overflow: hidden; }
button, a, [role="button"], label.chip, .row[data-act] { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }

#app { height: calc(100dvh - var(--hud-h, 0px)); display: flex; flex-direction: column; }
#top { position: relative; z-index: 5; padding: calc(var(--sat) + 10px) 16px 0; background: rgba(13,13,13,.72); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%); }
#top::after { content: ""; position: absolute; left: 0; right: 0; bottom: -14px; height: 14px; background: linear-gradient(var(--plane), transparent); pointer-events: none; }
.top-row { display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
.top-row h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); transition: transform 120ms var(--ease-out), background 120ms; }
.icon-btn:active { transform: scale(.92); background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.spin svg { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Objectius: sempre visibles */
.goals { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 10px; margin: 0 -16px; scrollbar-width: none; scroll-snap-type: x proximity; }
.goals::-webkit-scrollbar { display: none; }
.goal { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; background: var(--surface); border: 1px solid var(--hair); border-radius: 999px; scroll-snap-align: start; transition: transform 120ms var(--ease-out); }
.goal:active { transform: scale(.97); }
.goal .g-txt { display: grid; line-height: 1.15; text-align: left; }
.goal .g-name { font-size: 11px; color: var(--muted); max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal .g-val { font-size: 13px; font-weight: 600; }
.goal.add { padding: 6px 14px; color: var(--text-2); font-size: 13px; min-height: 42px; }
.ring { width: 30px; height: 30px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring .bg { stroke: var(--surface-3); }
.ring .fg { stroke-linecap: round; transition: stroke-dashoffset 500ms var(--ease-out); }

#main { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px calc(var(--tabs-h) + var(--sab) + 84px); outline: none; }
.stack { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r); padding: 14px; }
.card.tint-sav { border-color: color-mix(in srgb, var(--aqua) 45%, var(--hair)); background: linear-gradient(160deg, color-mix(in srgb, var(--aqua) 12%, var(--surface)), var(--surface) 55%); }
.card.tint-inv { border-color: color-mix(in srgb, var(--violet) 45%, var(--hair)); background: linear-gradient(160deg, color-mix(in srgb, var(--violet) 12%, var(--surface)), var(--surface) 55%); }
.card h2 { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .02em; text-transform: uppercase; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.hero { padding: 6px 2px 2px; }
.hero .label { color: var(--muted); font-size: 13px; }
.hero .big { font-size: clamp(34px, 11vw, 46px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; margin: 2px 0 8px; }
.deltas { display: flex; flex-wrap: wrap; gap: 6px; }
.delta { font-size: 12.5px; padding: 4px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--hair); color: var(--text-2); }
.up { color: var(--good); } .down { color: var(--bad); } .dim { color: var(--muted); }
.sub { color: var(--muted); font-size: 12.5px; }
.kv { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; padding: 5px 0; }
.kv + .kv { border-top: 1px solid var(--hair); }
.kv b { font-weight: 600; }
.big2 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { padding: 6px 11px; border-radius: 8px; font-size: 13px; color: var(--text-2); transition: background 150ms, color 150ms, transform 120ms var(--ease-out); }
.seg button:active { transform: scale(.96); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); font-weight: 600; }
.seg.wide { display: flex; } .seg.wide button { flex: 1; padding: 9px 6px; }

.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--hair); }
.row[data-act] { transition: opacity 120ms; } .row[data-act]:active { opacity: .6; }
.row .grow { flex: 1; min-width: 0; }
.row .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { text-align: right; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); vertical-align: 1px; margin-left: 4px; }
.badge.warn { color: #0b0b0b; background: var(--warn); }

/* barres */
.bar { height: 8px; background: var(--surface-3); border-radius: 4px; position: relative; overflow: visible; }
.bar i { display: block; height: 100%; border-radius: 4px; min-width: 2px; transition: width 500ms var(--ease-out); }
.bar .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 1px; }
.split { display: flex; height: 12px; gap: 2px; border-radius: 4px; overflow: hidden; }
.split i { display: block; min-width: 3px; border-radius: 2px; transition: flex-grow 500ms var(--ease-out); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.budget { display: grid; gap: 12px; }
.budget .b-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; gap: 8px; }
.budget .b-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.groups { display: grid; gap: 12px; }
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.cat { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--hair); font-size: 13.5px; }
.cat span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.cat.zero { opacity: .45; }
.period { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.period .p-nav { display: flex; align-items: center; gap: 2px; }
.period .p-label { display: inline-block; min-width: 132px; text-align: center; font-weight: 600; }
.period .p-label::first-letter, .day-h::first-letter, .tip b::first-letter { text-transform: uppercase; }

/* gràfics */
.chart { position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--surface-3); border: 1px solid var(--axis); border-radius: 10px; padding: 6px 9px; font-size: 12px; white-space: nowrap; transform: translateX(-50%); opacity: 0; transition: opacity 120ms; z-index: 2; }
.tip.on { opacity: 1; }
.tip b { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.tip span { display: flex; align-items: center; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 13.5px; }

/* botons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 14px; background: var(--text); color: #0d0d0d; font-weight: 600; transition: transform 120ms var(--ease-out), opacity 120ms; min-height: 46px; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.small { padding: 7px 12px; min-height: 34px; border-radius: 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; } .btn-row > * { flex: 1; }
.link { color: var(--blue); font-size: 13.5px; padding: 6px 0; }

/* barra inferior */
#tabs { position: fixed; left: 0; right: 0; bottom: var(--hud-h, 0px); z-index: 6; display: grid; grid-template-columns: 1fr 1fr 64px 1fr 1fr; align-items: center; height: calc(var(--tabs-h) + var(--sab)); padding: 0 6px var(--sab); background: rgba(22,22,21,.78); backdrop-filter: blur(22px) saturate(170%); -webkit-backdrop-filter: blur(22px) saturate(170%); border-top: 1px solid rgba(255,255,255,.07); }
.tab { display: grid; justify-items: center; gap: 2px; font-size: 10.5px; color: var(--muted); padding: 6px 0; transition: color 150ms, transform 120ms var(--ease-out); }
.tab:active { transform: scale(.94); }
.tab svg { width: 23px; height: 23px; }
.tab[aria-current="page"] { color: var(--text); }
.fab { width: 54px; height: 54px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; justify-self: center; transform: translateY(-14px); box-shadow: 0 8px 24px rgba(57,135,229,.35), 0 2px 6px rgba(0,0,0,.5); transition: transform 140ms var(--ease-out); }
.fab:active { transform: translateY(-14px) scale(.92); }
.fab svg { width: 26px; height: 26px; }

/* full inferior */
#scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.55); opacity: 0; }
#sheet { position: fixed; left: 0; right: 0; bottom: var(--hud-h, 0px); z-index: 11; max-height: calc(100dvh - var(--hud-h, 0px) - var(--sat) - 28px); display: flex; flex-direction: column; background: var(--surface); border-radius: 22px 22px 0 0; border-top: 1px solid rgba(255,255,255,.1); box-shadow: 0 -18px 50px rgba(0,0,0,.6); will-change: transform; }
.sheet-grab { padding: 8px 0 4px; touch-action: none; cursor: grab; flex: 0 0 auto; }
.sheet-grab i { display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--axis); margin: 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 8px 8px 18px; touch-action: none; flex: 0 0 auto; }
.sheet-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 18px calc(18px + var(--sab)); display: grid; gap: 14px; align-content: start; }
.field { display: grid; gap: 6px; }
.field > span, .lbl { font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--hair); border-radius: 12px; padding: 12px; outline: none; transition: border-color 150ms; }
.field input:focus, .field select:focus { border-color: var(--blue); }
.field.amount input { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; padding: 10px 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 8px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--hair); font-size: 13.5px; color: var(--text-2); transition: transform 120ms var(--ease-out), background 150ms; }
.chip:active { transform: scale(.95); }
.chip[aria-pressed="true"] { background: var(--text); color: #0d0d0d; border-color: var(--text); font-weight: 600; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.switch input { appearance: none; width: 48px; height: 28px; border-radius: 999px; background: var(--surface-3); position: relative; transition: background 180ms; flex: 0 0 auto; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 200ms var(--ease-out); }
.switch input:checked { background: var(--good); } .switch input:checked::after { transform: translateX(20px); }
.err { color: var(--bad); font-size: 13.5px; min-height: 1.2em; }
.note { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.list-edit .row input { background: transparent; border: 0; padding: 4px 0; width: 100%; outline: none; }
.day-h { font-size: 12px; color: var(--muted); padding: 14px 2px 4px; }
.tx-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); flex: 0 0 auto; font-size: 15px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--sab) + var(--hud-h, 0px) + 26px); transform: translate(-50%, 20px); background: var(--text); color: #0d0d0d; padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 200ms, transform 300ms var(--ease-out); z-index: 20; max-width: 88vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 620px) { #app, #tabs, #sheet { max-width: 520px; margin: 0 auto; } #tabs, #sheet { left: 50%; right: auto; width: 520px; margin-left: -260px; } }
@media (hover: hover) and (pointer: fine) { .chip:hover, .seg button:hover { color: var(--text); } .icon-btn:hover { background: var(--surface-2); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; } }
@media (prefers-reduced-transparency: reduce) { #top, #tabs { background: var(--plane); backdrop-filter: none; -webkit-backdrop-filter: none; } }
.top-acts { display: flex; flex: 0 0 auto; }
.top-row h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
