:root {
  --bg: #14121f;
  --bg2: #1c1930;
  --card: #231f3a;
  --card2: #2b2748;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f1eefc;
  --muted: #9d97bd;
  --accent: #8b6cff;
  --accent-ink: #fff;
  --pos: #3ddc97;
  --neg: #ff6b8b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --r: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Text", system-ui, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f3ff;
    --bg2: #ede8fb;
    --card: #ffffff;
    --card2: #f1edff;
    --line: rgba(60, 40, 120, 0.12);
    --text: #231c3d;
    --muted: #7a7298;
    --pos: #15a36a;
    --neg: #e0456a;
    --shadow: 0 10px 30px rgba(80, 60, 160, 0.14);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100dvh; background: radial-gradient(900px 500px at 50% -10%, var(--bg2), var(--bg)); background-attachment: fixed; }
button, input, select { font: inherit; color: inherit; }
html { overscroll-behavior-y: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
input { -webkit-user-select: text; user-select: text; }
button { cursor: pointer; border: 0; background: none; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 16px calc(120px + env(safe-area-inset-bottom)); }

/* cabecera */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.top h1 { font-size: 1.25rem; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.icon-btn { width: 40px; height: 40px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 1.1rem; }
.icon-btn:active { transform: scale(0.94); }
.monthnav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 6px; margin-bottom: 14px; }
.monthnav .label { font-weight: 650; text-transform: capitalize; }
.monthnav button { width: 40px; height: 36px; border-radius: 12px; font-size: 1.2rem; }
.monthnav button:active { background: var(--card2); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px; margin-bottom: 14px; }
.tabs button { padding: 9px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }

/* tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 12px; font-weight: 650; }
.balance { text-align: center; padding: 20px 16px; background: linear-gradient(160deg, var(--accent), #5b3df0); color: #fff; border: 0; }
.balance .lbl { font-size: 0.78rem; opacity: 0.85; color: #fff; margin: 0; text-transform: uppercase; letter-spacing: 0.08em; }
.balance .big { font-size: 2.3rem; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.balance .row { display: flex; justify-content: center; gap: 12px; }
.balance .row div { font-size: 0.78rem; }
.balance .row div { padding: 8px 16px; border-radius: 14px; }
.balance .row .in { background: rgba(61, 220, 151, 0.2); color: #8bffc8; }
.balance .row .out { background: rgba(255, 107, 139, 0.22); color: #ffa3b8; }
.balance .row b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.balance .sub { margin-top: 12px; font-size: 0.78rem; opacity: 0.8; }

/* categorías */
.stack { display: flex; height: 12px; border-radius: 8px; overflow: hidden; background: var(--card2); margin-bottom: 14px; }
.stack i { display: block; height: 100%; }
.catrow { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; width: 100%; text-align: left; border-radius: 12px; }
.catrow + .catrow { border-top: 1px solid var(--line); }
.catrow:active { background: var(--card2); }
.cat-ico { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; font-size: 1.25rem; }
.catrow .name { font-weight: 600; font-size: 0.95rem; }
.catrow .meta { font-size: 0.75rem; color: var(--muted); }
.catrow .amt { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.bar { height: 6px; border-radius: 4px; background: var(--card2); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.bar.over i { background: var(--neg) !important; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 0.92rem; }

/* movimientos */
.filters { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chip { padding: 7px 13px; border-radius: 999px; background: var(--card2); color: var(--muted); font-size: 0.85rem; font-weight: 600; border: 1px solid transparent; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.day { font-size: 0.78rem; color: var(--muted); font-weight: 650; margin: 14px 2px 6px; text-transform: capitalize; display: flex; justify-content: space-between; }
.tx { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 8px; border-radius: 16px; }
.tx:active { background: var(--card2); }
.tx .name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .meta { font-size: 0.76rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tx .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.tx .amt.in { color: var(--pos); }
.tag { font-size: 0.68rem; padding: 2px 7px; border-radius: 999px; background: var(--card2); color: var(--muted); font-weight: 650; }


/* hoja inferior */
.scrim { position: fixed; inset: 0; background: rgba(8, 6, 18, 0.6); z-index: 40; animation: fade 0.2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 560px; margin: 0 auto; background: var(--bg2); border-radius: 26px 26px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto; box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4); animation: up 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
.sheet .grab { width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 1.1rem; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--card); border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.seg button { padding: 10px; border-radius: 11px; font-weight: 650; color: var(--muted); }
.seg button.on.exp { background: var(--neg); color: #fff; }
.seg button.on.inc { background: var(--pos); color: #fff; }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 4px 0 14px; }
.amount input { width: 9ch; max-width: 60%; text-align: center; font-size: 2.6rem; font-weight: 750; background: none; border: 0; outline: none; font-variant-numeric: tabular-nums; }
.amount span { font-size: 1.6rem; color: var(--muted); font-weight: 650; }
.lbl { font-size: 0.75rem; color: var(--muted); font-weight: 650; margin: 12px 2px 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.catbtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px 8px; border-radius: 16px; background: var(--card); border: 2px solid transparent; font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.15; min-width: 0; }
.catbtn .e { font-size: 1.5rem; }
.catbtn span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbtn.on { border-color: var(--accent); background: var(--card2); }
.catbtn.add { border: 2px dashed var(--line); color: var(--muted); background: none; }
input.field, select.field { font-size: 16px; width: 100%; padding: 13px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); outline: none; }
input.field:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--card); margin-top: 8px; width: 100%; text-align: left; }
.switch small { display: block; color: var(--muted); font-size: 0.74rem; }
.switch .tg { width: 44px; height: 26px; border-radius: 14px; background: var(--card2); position: relative; flex: none; transition: background 0.2s; }
.switch .tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch.on .tg { background: var(--accent); }
.switch.on .tg::after { transform: translateX(18px); }
.btn { padding: 14px; border-radius: 16px; font-weight: 700; width: 100%; background: var(--card); border: 1px solid var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.btn.danger { color: var(--neg); }
.btn:active { transform: scale(0.98); }
.actions { display: grid; gap: 8px; margin-top: 16px; }
.actions.row { grid-template-columns: 1fr 2fr; }
.newcat { background: var(--card); border-radius: 18px; padding: 14px; margin-top: 10px; }
.emojis { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.emojis button { width: 38px; height: 38px; border-radius: 12px; font-size: 1.3rem; background: var(--card2); border: 2px solid transparent; }
.emojis button.on { border-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--text); }

/* año */
.years { display: flex; gap: 6px; align-items: center; justify-content: center; margin-bottom: 14px; }
.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 150px; padding-top: 6px; }
.chart .m { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 2px; }
.chart .pair { display: flex; align-items: flex-end; gap: 2px; height: 120px; width: 100%; justify-content: center; }
.chart .pair i { display: block; width: 38%; border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .m small { font-size: 0.6rem; color: var(--muted); text-transform: capitalize; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 0.75rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.92rem; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv b { font-variant-numeric: tabular-nums; }

/* login */
.login-body { display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 26px; padding: 28px 22px; display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.login-card .logo { font-size: 2.6rem; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-card input { font-size: 16px; padding: 14px; border-radius: 14px; background: var(--bg2); border: 1px solid var(--line); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.err { color: var(--neg); font-size: 0.88rem; }

.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.88rem; font-weight: 600; z-index: 80; box-shadow: var(--shadow); }
.savestate { font-size: 0.72rem; color: var(--muted); }

/* barra inferior tipo app */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 84px 1fr; align-items: center; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; color: var(--muted); font-size: 0.7rem; font-weight: 650; border-radius: 14px; transition: transform 0.12s; }
.nav button b { font-size: 1.3rem; filter: grayscale(1) opacity(0.6); transition: filter 0.2s; }
.nav button.on { color: var(--text); }
.nav button.on b { filter: none; }
.nav button:active { transform: scale(0.92); }
.nav .plus { padding: 0; }
.nav .plus i { width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; background: var(--accent); color: #fff; font-style: normal; font-size: 2rem; line-height: 1; display: grid; place-items: center; box-shadow: 0 10px 24px rgba(139, 108, 255, 0.5); border: 4px solid var(--bg); }

/* hoja inferior: cabecera fija, centro con scroll, pie fijo (teclado y Guardar siempre a la vista) */
.sheet { position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 50; max-width: 560px; margin: 0 auto; background: var(--bg2); border-radius: 26px 26px 0 0; display: flex; flex-direction: column; max-height: calc(var(--vvh, 100dvh) - 14px); overflow: hidden; box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4); animation: up 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
.grab-area { padding: 10px 0 8px; touch-action: none; flex: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 0 auto; }
.sheet h3 { margin: 4px 0 12px; font-size: 1.1rem; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 18px; -webkit-overflow-scrolling: touch; }
.sheet-foot { flex: none; padding: 8px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg2); }
.sheet.kb .keypad { display: none; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keypad button { height: 46px; border-radius: 14px; background: var(--card); font-size: 1.35rem; font-weight: 600; transition: transform 0.08s, background 0.1s; }
.keypad button:active { transform: scale(0.94); background: var(--card2); }
.amount span.ph { color: var(--muted); opacity: 0.5; }
.amount > span:first-child { font-size: 2.8rem; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.amount { margin: 2px 0 10px; }
.catbtn:active { transform: scale(0.94); }
.tx, .catrow, .chip, .icon-btn, .btn { transition: transform 0.1s, background 0.15s; }
@media (max-height: 700px) { .keypad button { height: 40px; } }

/* cuentas (banco / efectivo) */
.acct { padding: 14px 16px; margin-bottom: 10px; }
.acct-h { display: flex; justify-content: space-between; align-items: center; }
.acct-h small { font-size: 0.78rem; color: var(--muted); font-weight: 650; }
.mini { padding: 6px 12px; border-radius: 999px; background: var(--card2); font-size: 0.8rem; font-weight: 650; border: 1px solid var(--line); }
.mini:active { transform: scale(0.94); }
.acct-amt { display: block; font-size: 1.9rem; font-weight: 750; letter-spacing: -0.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.acct-amt.pos, .t-in { color: var(--pos); }
.acct-amt.neg, .t-out { color: var(--neg); }
.acct-sub { font-size: 0.76rem; color: var(--muted); line-height: 1.5; }
.acct-sub b { font-weight: 650; }
.balance .big.pos { color: #8bffc8; }
.balance .big.neg { color: #ffa3b8; }
.notice { display: block; width: 100%; text-align: left; font-size: 0.9rem; line-height: 1.45; }
.notice b { color: var(--accent); }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg.three button.on.trf, .seg.acct button.on { background: var(--accent); color: #fff; }
.hint { background: var(--card); border-radius: 14px; padding: 14px; margin: 6px 0; font-size: 0.9rem; color: var(--muted); line-height: 1.45; }
.tx .amt.tr { color: var(--muted); }
/* gráfico del año */
.ychart svg { width: 100%; height: auto; display: block; }
.ychart .b-in { fill: var(--pos); }
.ychart .b-out { fill: var(--neg); }
.ychart .zero { stroke: var(--line); stroke-width: 1; }
.ychart .sav-line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ychart .dot { fill: var(--bg2); stroke: var(--accent); stroke-width: 2; }
.ychart text { fill: var(--muted); font-size: 8.5px; text-transform: capitalize; }
.ychart .ysel { fill: var(--accent); opacity: 0.14; }
.ychart .hit { fill: transparent; cursor: pointer; }
.legend i.ln { width: 14px; height: 3px; border-radius: 2px; background: var(--accent); vertical-align: middle; }
.ydetail { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.ydetail span b { font-variant-numeric: tabular-nums; }
.ydetail.muted { justify-content: center; }

/* tarjetas de banco y efectivo: mismo estilo que el balance, con Cuadrar arriba a la derecha */
.balance.acct { position: relative; padding: 18px 16px 16px; margin-bottom: 10px; }
.balance.acct .lbl { font-size: 0.72rem; text-align: left; padding: 8px 0 0 2px; }
.balance.acct .big { font-size: 2.3rem; margin: 0 0 10px; }
.balance.acct .sub { margin-top: 0; line-height: 1.5; }
.balance.acct .mini { position: absolute; top: 10px; right: 10px; background: rgba(255, 255, 255, 0.2); color: #fff; border: 0; padding: 6px 12px; }
.balance .t-in { color: #8bffc8; }
.balance .t-out { color: #ffa3b8; }

.pill-btn { height: 40px; padding: 0 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; font-weight: 650; }
.pill-btn:active { transform: scale(0.95); }
.balance.acct .row { margin-top: 2px; }
.balance.acct .sub.now { margin-top: 10px; }
.balance.acct .sub + .sub { margin-top: 4px; }
.balance.acct .row + .sub { margin-top: 14px; }

/* el + del botón central se dibuja con dos barras: así queda siempre centrado en el círculo */
.nav .plus i { position: relative; font-size: 0; line-height: 0; }
.nav .plus i::before, .nav .plus i::after { content: ""; position: absolute; left: 50%; top: 50%; background: #fff; border-radius: 2px; transform: translate(-50%, -50%); }
.nav .plus i::before { width: 22px; height: 3.5px; }
.nav .plus i::after { width: 3.5px; height: 22px; }
