:root {
  --bg: #0b1220; --surface: #141d30; --surface-2: #1b2740; --border: #26334b;
  --text: #eef2f8; --muted: #93a4c0; --pos: #34d399; --neg: #fb7185; --blue: #60a5fa;
  --radius: 18px; --radius-sm: 13px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; overflow-x: hidden; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; height: 100%; overflow-x: hidden;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overscroll-behavior-y: none;
  font-size: 16px; line-height: 1.4;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
.muted { color: var(--muted); }
svg { display: block; }

/* ── Layout ───────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 480px; margin: 0 auto; position: relative; }

.appbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(12px + var(--safe-t)) 14px 12px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg), rgba(11,18,32,.85)); backdrop-filter: blur(10px);
}
.icon-btn { background: var(--surface); border: 1px solid var(--border); width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; stroke: var(--text); }
.month-nav { flex: 1; display: flex; align-items: center; justify-content: center; gap: 2px; }
.month-nav button { background: none; border: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.month-nav button:active { background: var(--surface); }
.month-nav button svg { width: 22px; height: 22px; stroke: var(--muted); }
#monthLbl { font-weight: 700; font-size: 1.02rem; min-width: 130px; text-align: center; }

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 14px calc(120px + var(--safe-b)); }

/* ── Hero (ahorro) ────────────────────────────────────────────────── */
.hero {
  border-radius: 22px; padding: 24px 20px; text-align: center; position: relative; overflow: hidden;
  background: radial-gradient(120% 100% at 50% 0%, #172942 0%, #101a2c 70%);
  border: 1px solid var(--border);
}
.hero-lbl { font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hero-val { font-size: 2.6rem; font-weight: 800; margin: 6px 0 16px; letter-spacing: -.02em; }
.hero-val.pos { color: var(--pos); } .hero-val.neg { color: var(--neg); }
.hero-io { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pill { background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 14px; padding: 11px; }
.pill span { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.pill b { font-size: 1.08rem; }
.pill b.pos { color: var(--pos); } .pill b.neg { color: var(--neg); }

/* ── Lista ────────────────────────────────────────────────────────── */
.group-h { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 22px 4px 10px; }
.mov {
  display: flex; align-items: center; gap: 13px; padding: 12px 14px; margin-bottom: 9px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.mov:active { background: var(--surface-2); }
.cat-ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; flex: none; }
.mov .info { flex: 1; min-width: 0; }
.mov .cat { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mov .sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.mov .amt { font-weight: 800; white-space: nowrap; font-size: 1.02rem; }
.amt.gasto { color: var(--neg); } .amt.ingreso { color: var(--pos); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ── FAB ──────────────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: calc(24px + var(--safe-b)); right: max(18px, calc(50% - 240px + 18px));
  width: 60px; height: 60px; border-radius: 20px; border: none; background: var(--pos); color: #052616;
  display: grid; place-items: center; box-shadow: 0 10px 26px rgba(52,211,153,.38); z-index: 20;
}
.fab svg { width: 28px; height: 28px; stroke: #052616; stroke-width: 2.6; }
.fab:active { transform: scale(.93); }

/* ── Sheets ───────────────────────────────────────────────────────── */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 30; }
.sheet-back.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; width: 100%; max-width: 480px; transform: translateY(100%);
  background: var(--bg); border: 1px solid var(--border); border-bottom: none; border-radius: 24px 24px 0 0;
  padding: 6px 20px calc(24px + var(--safe-b)); z-index: 40; max-height: 94dvh; overflow-y: auto;
  transition: transform .28s cubic-bezier(.32,.72,0,1);
}
.sheet.open { transform: translateY(0); }
.grip { width: 42px; height: 5px; background: var(--surface-2); border-radius: 3px; margin: 8px auto 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet h2 { font-size: 1.18rem; margin: 0; }
.hint { color: var(--muted); font-size: .82rem; margin: 4px 0 14px; }
.add-link { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: .85rem; font-weight: 600; color: var(--pos); }

/* ── Formularios ──────────────────────────────────────────────────── */
label { display: block; font-size: .8rem; color: var(--muted); margin: 16px 0 7px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 14px; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; -webkit-appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--blue); }
.help { display: block; font-size: .72rem; color: var(--muted); margin-top: 5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: .9rem; margin-top: 16px; }
.check input { width: 22px; height: 22px; flex: none; }

.amount-wrap { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 14px 0 4px; }
.amount-wrap .cur { font-size: 2rem; font-weight: 700; color: var(--muted); }
.amount-input { width: auto; max-width: 62%; font-size: 2.6rem; font-weight: 800; text-align: center; border: none; background: none; padding: 8px 0; }
.amount-input:focus { outline: none; }

.seg { display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 5px; }
.seg.tipo { margin-top: 8px; }
.seg button { flex: 1; padding: 11px; border-radius: 10px; border: none; background: none; color: var(--muted); font-weight: 700; }
.seg button.on-gasto { background: var(--neg); color: #2b0710; }
.seg button.on-ingreso { background: var(--pos); color: #052616; }

.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: .92rem; }
.chip .cdot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { border-color: var(--pos); background: rgba(52,211,153,.12); }
.persona .chip.on { border-color: var(--blue); background: rgba(96,165,250,.14); }

.btn { width: 100%; margin-top: 22px; padding: 16px; font-size: 1.05rem; font-weight: 700; color: #052616; background: var(--pos); border: none; border-radius: 14px; }
.btn:active { filter: brightness(.94); }
.btn.ghost { background: none; color: var(--muted); border: 1px solid var(--border); margin-top: 10px; }
.btn.danger { background: none; color: var(--neg); border: 1px solid var(--neg); }
.err { color: var(--neg); font-size: .88rem; margin-top: 12px; min-height: 1.1em; text-align: center; }
.fijo-note { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: .85rem; color: var(--muted); margin-top: 16px; }

/* ── Fijos (lista) ────────────────────────────────────────────────── */
.fijo { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 9px; }
.fijo:active { background: var(--surface-2); }
.fijo.off { opacity: .5; }
.fijo .fdot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.fijo .fname { font-weight: 600; }
.fijo .fmeta { font-size: .76rem; color: var(--muted); margin-top: 2px; }
.fijo .famt { font-weight: 800; margin-left: auto; white-space: nowrap; }
.badge { font-size: .6rem; padding: 3px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; margin-left: 8px; }
.badge.temp { background: rgba(96,165,250,.16); color: #93c5fd; }
