:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66716c;
  --line: #e3e6e1;
  --accent: #0f766e;
  --accent-soft: #d8efe9;
  --pos: #15803d;
  --neg: #c2410c;
  --neg-soft: #fde8dd;
  --warn: #b45309;
  --chip: #eef0ec;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 16px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --card: #17201d;
    --text: #e8eeeb;
    --muted: #93a19b;
    --line: #26322e;
    --accent: #2dd4bf;
    --accent-soft: #123c36;
    --pos: #4ade80;
    --neg: #fb923c;
    --neg-soft: #3b2216;
    --warn: #fbbf24;
    --chip: #1f2a26;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 24px; margin: 12px 0 28px; }
.login form { display: grid; gap: 12px; }
.login input { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 17px; }
.error { color: var(--neg); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.icon-btn { background: none; border: 0; padding: 8px; margin-right: -8px; border-radius: 10px; color: var(--muted); }
main { padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 88px); max-width: 640px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button { background: none; border: 0; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 11px; }
.tabbar button.active { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 7;
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(15, 118, 110, .35);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }
@media (prefers-color-scheme: dark) { .fab { color: #062a26; } }

/* ---------- Tarjetas ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head h2 { margin-bottom: 10px; }
.link { background: none; border: 0; color: var(--accent); font-size: 14px; padding: 0; font-weight: 600; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.mid { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-val { font-weight: 650; }

.bar { height: 10px; border-radius: 99px; background: var(--chip); overflow: hidden; margin-top: 12px; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s; }
.bar.over > i { background: var(--neg); }
.bar.thin { height: 6px; margin-top: 8px; }

/* ---------- Pasos del mes ---------- */
.step { padding: 12px 0; border-top: 1px solid var(--line); }
.step:first-of-type { border-top: 0; padding-top: 2px; }
.step-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.step-name { font-weight: 600; }
.step-detail { font-size: 13px; color: var(--muted); margin-top: -4px; margin-bottom: 8px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg button.on.si { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on.si { color: #062a26; } }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
button.item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; padding-left: 0; padding-right: 0; }
.list li:first-child > button.item { border-top: 0; }
.dot { width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; font-size: 17px; }
.item-main { flex: 1; min-width: 0; }
.item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.item-sub { font-size: 13px; color: var(--muted); }
.item-amt { font-weight: 650; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-left: 4px; vertical-align: 1px; }
.day-head { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 4px 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 15px; }

/* Resumen categorías */
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 0; }
.cat-row .bar { grid-column: 1 / -1; margin-top: 2px; }

/* Selector de mes */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 99px; font-size: 14px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Bolsas */
.bolsa { display: block; width: 100%; text-align: left; border: 0; }
.bolsa .row { align-items: flex-start; }
.bolsa-name { font-weight: 650; }
.bolsa-where { font-size: 13px; color: var(--muted); margin-top: 2px; }
.bolsa-saldo { font-size: 22px; font-weight: 700; white-space: nowrap; }
.bolsa-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.bolsa.negativa .bolsa-saldo { color: var(--neg); }

/* Meses */
.mes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; margin-top: 12px; }
.mes-name { font-weight: 700; font-size: 17px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }

/* ---------- Botones ---------- */
.btn { border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 600; font-size: 16px; background: var(--chip); }
.btn.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062a26; } }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* ---------- Hoja inferior ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 92dvh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(18px + var(--safe-b));
  max-width: 640px; margin: 0 auto;
  animation: up .22s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 16px; font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; appearance: none; -webkit-appearance: none;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.amount-input { font-size: 34px !important; font-weight: 700; text-align: center; padding: 10px !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-pick button { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 8px 12px; font-size: 14px; }
.cat-pick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .cat-pick button.on { color: #062a26; } }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; margin: 4px 0 16px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { display: grid; gap: 10px; margin-top: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tab-h) + var(--safe-b) + 90px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); animation: fade .2s;
}
.toast.err { background: var(--neg); color: #fff; }
