:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #17202c;
  --muted: #677487;
  --line: #e3e8ef;
  --accent: #4f7cff;
  --accent-soft: #e8eeff;
  --pos: #16995a;
  --neg: #d6453d;
  --warn: #e0a100;
  --inc: #2bb673;
  --exp: #ff7a59;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --card: #19212c;
    --text: #e8edf4;
    --muted: #93a0b2;
    --line: #2a3442;
    --accent: #7096ff;
    --accent-soft: #1f2b47;
    --pos: #3ccf86;
    --neg: #ff6b62;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f141b;
    --card: #19212c;
    --text: #e8edf4;
    --muted: #93a0b2;
    --line: #2a3442;
    --accent: #7096ff;
    --accent-soft: #1f2b47;
    --pos: #3ccf86;
    --neg: #ff6b62;
    --shadow: none;
  color-scheme: dark;
}


* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h3 { margin: 0 0 12px; font-size: 1.05rem; }
h4 { margin: 0; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.sync {
  display: flex; align-items: center; gap: 8px; max-width: 60vw;
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: .82rem; color: var(--muted);
}
.sync span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync.ok i { background: var(--pos); }
.sync.err i { background: var(--neg); }
.sync.busy i { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Navegación: abajo en teléfono, arriba en pantallas grandes */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .7rem; color: var(--muted);
}
.tabs button span { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active span { filter: none; opacity: 1; }

.monthbar, #view { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.monthbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthbar[hidden] { display: none; }
.monthbar b { font-size: 1.05rem; }
.monthbar b::first-letter, .day::first-letter { text-transform: uppercase; }
.monthbar button:disabled { opacity: .35; cursor: default; }
.monthbar button {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 1.4rem; line-height: 1;
}

@media (min-width: 800px) {
  body { padding-bottom: 40px; }
  .tabs {
    position: sticky; top: 58px; bottom: auto; height: auto; max-width: 760px; margin: 0 auto 16px;
    border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; z-index: 4;
  }
  .tabs button { flex-direction: row; gap: 6px; font-size: .9rem; padding: 8px; border-radius: 10px; }
  .tabs button span { font-size: 1rem; }
  .tabs button.active { background: var(--accent-soft); }
  .fab { bottom: 32px !important; }
  .top { padding-left: max(16px, calc((100% - 760px) / 2 + 16px)); padding-right: max(16px, calc((100% - 760px) / 2 + 16px)); }
}

/* Tarjetas */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; margin-bottom: 14px;
}
.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.cards3 .card { margin: 0; padding: 12px; }
.stat small { display: block; color: var(--muted); font-size: .78rem; }
.stat b { display: block; font-size: clamp(.8rem, 3.9vw, 1.05rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
@media (min-width: 600px) { .stat b { font-size: 1.3rem; } }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

/* Mi dinero */
.moneyhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.moneyhead b { font-size: 1.5rem; letter-spacing: -.01em; }
.acclist { list-style: none; margin: 4px 0 0; padding: 0; }
.acclist li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 4px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px;
}
.acclist li:active { background: var(--accent-soft); }
.accicon { font-size: 1.2rem; text-align: center; }
.acclist b, .stat b, .txlist span, .legend b { font-variant-numeric: tabular-nums; }
.neutral { color: var(--muted); }

/* Semana de pago */
.weekhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.weekhead h3 { margin: 0; }
.weekhead .muted { margin: 0; text-transform: capitalize; }
.weekgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 10px; }
.weekgrid > div { min-width: 0; }
.weekgrid small { display: block; color: var(--muted); font-size: .78rem; }
.weekgrid b { display: block; font-variant-numeric: tabular-nums; font-size: clamp(.85rem, 3.9vw, 1.1rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.payok { color: var(--pos); font-weight: 600; font-size: .9rem; margin: 10px 0 0; }
.week .btn.wide { margin-top: 12px; }
.field { margin-bottom: 12px; }
.field .seg { margin: 4px 0 0; }
.flabel { display: block; font-size: .85rem; color: var(--muted); }

/* Barras de progreso */
.progress { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--pos); border-radius: inherit; transition: width .3s; }
.progress.warn span { background: var(--warn); }
.progress.over span { background: var(--neg); }
.progress.goalp span { background: var(--accent); }
.progress.debt span { background: #a35bff; }

/* Dona */
.donutwrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.donut {
  width: 170px; height: 170px; border-radius: 50%; flex: none; margin: 0 auto;
  display: grid; place-items: center;
}
.donut > div {
  width: 62%; height: 62%; border-radius: 50%; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 6px;
}
.donut small { color: var(--muted); font-size: .75rem; }
.donut b { font-size: .9rem; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 220px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto 44px; gap: 8px; align-items: center; padding: 5px 0; font-size: .9rem; }
.legend i { width: 12px; height: 12px; border-radius: 4px; }
.legend em { color: var(--muted); font-style: normal; text-align: right; font-size: .8rem; }

/* Barras 6 meses */
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; height: 160px; align-items: end; }
.bcol { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 6px; }
.bpair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bpair span { width: 40%; max-width: 22px; border-radius: 5px 5px 0 0; min-height: 2px; }
.bi { background: var(--inc); }
.be { background: var(--exp); }
.bcol small { color: var(--muted); font-size: .75rem; text-transform: capitalize; }
.bcol.cur small { color: var(--text); font-weight: 700; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 2px 0 8px; vertical-align: -1px; }

/* Movimientos */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; font-size: .9rem; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.day { color: var(--muted); font-size: .8rem; font-weight: 600; margin: 14px 4px 6px; }
.txlist { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.txlist li { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.txlist li + li { border-top: 1px solid var(--line); }
.txlist li:active { background: var(--accent-soft); }
.txlist i { width: 10px; height: 32px; border-radius: 5px; }
.txlist small { display: block; color: var(--muted); font-size: .82rem; }
.txlist span { font-weight: 600; white-space: nowrap; }

/* Presupuesto y metas */
.budrow { padding: 12px 0; border-top: 1px solid var(--line); }
.budhead { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.budhead .muted { margin: 0; }
.budinput { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: .85rem; color: var(--muted); }
.budinput input { width: 150px; }
.goal + .goal { margin-top: 16px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Formularios */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; /* 16px evita zoom en iPhone */
}
input[type=checkbox] { width: 20px; height: 20px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn {
  border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 16px; font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { color: var(--neg); }
.btn.wide { width: 100%; margin-top: 8px; }
.btngrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(440px, calc(100vw - 24px));
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog .seg { margin-top: 4px; }
dialog.ask { width: min(360px, calc(100vw - 32px)); }
dialog.ask p { margin: 0 0 8px; font-size: 1rem; }
.btn.dangerfill { background: var(--neg); color: #fff; }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 7;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 20px rgba(79, 124, 255, .45);
}
.fab[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px); z-index: 20;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  transition: .25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* Pantallas de ingreso y bloqueo */
body.gated > .top, body.gated > .tabs, body.gated > #monthbar, body.gated > main, body.gated > .fab { display: none !important; }
.gate {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 24px) max(20px, env(safe-area-inset-left));
}
.gatebox { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: stretch; text-align: center; gap: 4px; }
.gatebox .form { text-align: left; margin-top: 12px; }
.gatelogo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 8px; box-shadow: var(--shadow); }
.gate h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.01em; }
.gatesub { color: var(--muted); margin: 4px 0 8px; }
.btn.big { padding: 14px 16px; font-size: 1.05rem; margin-top: 16px; }
.btn:disabled { opacity: .6; }
.linkbtn { background: none; border: 0; color: var(--accent); padding: 10px; font-size: .95rem; }
.autherr { color: var(--neg); font-size: .9rem; margin: -4px 0 10px; }

/* Ajustes: cuenta */
.acctline { margin: 0; overflow-wrap: anywhere; }
.lockrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); margin-top: 12px; }
.lockrow small { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.lockrow .btn { flex: none; }

/* Administración */
.tabs button { position: relative; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--neg); color: #fff; font-size: .7rem; font-style: normal; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
@media (min-width: 800px) { .badge { position: static; margin-left: 4px; } }
.urow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.uinfo { min-width: 0; flex: 1 1 220px; }
.uinfo b { display: block; overflow-wrap: anywhere; }
.uinfo small { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: .82rem; margin-top: 4px; }
.uacts { display: flex; gap: 8px; flex-wrap: wrap; }
.uacts .btn { padding: 8px 12px; font-size: .9rem; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--line); color: var(--muted); }
.chip.ok { background: color-mix(in srgb, var(--pos) 18%, transparent); color: var(--pos); }
.chip.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--neg) 18%, transparent); color: var(--neg); }
.viewer { border-color: var(--accent); }
.viewhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.viewhead h3 { margin: 0; overflow-wrap: anywhere; }
.viewer .moneyhead { margin-top: 8px; }
.ro li { cursor: default; }
.authnote { font-size: .85rem; color: var(--muted); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin: -2px 0 12px; }
.statusicon { font-size: 2.6rem; margin-top: 16px; }
.statustitle { margin: 6px 0 0; font-size: 1.15rem; }
.authhint { font-size: .82rem; color: var(--muted); margin: -6px 0 12px; }
.authfoot { font-size: .8rem; color: var(--muted); margin: 14px 0 0; line-height: 1.5; }
.addform { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.addform .addprev, .addform .autherr, .addform .row-end { grid-column: 1 / -1; }
.addprev { margin: -6px 0 4px; }
@media (max-width: 520px) { .addform { grid-template-columns: 1fr; } }
.creds { margin-top: 14px; padding: 14px; border-radius: 12px; background: color-mix(in srgb, var(--pos) 12%, transparent); border: 1px solid color-mix(in srgb, var(--pos) 35%, transparent); }
.creds pre { white-space: pre-wrap; overflow-wrap: anywhere; font: .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--card); border-radius: 8px; padding: 10px 12px; margin: 10px 0 0; user-select: all; }
.lockuser { font-weight: 600; margin: 0 0 4px; overflow-wrap: anywhere; }
.btn.faceid { display: flex; align-items: center; justify-content: center; gap: 10px; }
.linkbtn.subtle { color: var(--muted); font-size: .85rem; padding-top: 2px; }
.btn.outline { background: var(--card); color: var(--text); border: 1px solid var(--line); margin-top: 10px; }
#authSubmit { margin-top: 4px; }
.steps { margin: 0 0 4px; padding-left: 20px; display: grid; gap: 6px; font-size: .92rem; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.namerow { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.namerow label { flex: 1; margin-bottom: 0; }
.namerow .btn { flex: none; }
.uinfo small + small { margin-top: 2px; }
.brand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.budinput label { color: var(--muted); }
.budctl { display: flex; align-items: center; gap: 6px; }
.iconbtn { width: 36px; height: 36px; flex: none; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: .9rem; }
.iconbtn:hover { color: var(--neg); border-color: var(--neg); }
.budrow + .row-end, .budrow ~ .row-end { padding-top: 14px; border-top: 1px solid var(--line); margin-top: 0; }

/* Comodidad móvil: superficies, jerarquía y controles táctiles. */
:root { --radius: 22px; --nav-h: 76px; --accent: #4869df; --shadow: 0 6px 24px rgba(26, 43, 76, .045); }
body { letter-spacing: -.015em; }
button, a, input, select { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.top { padding-top: calc(env(safe-area-inset-top) + 16px); padding-bottom: 16px; }
.brand { font-weight: 800; letter-spacing: -.04em; }
.sync { min-height: 44px; max-width: 48%; }
.monthbar { margin-top: 6px; margin-bottom: 20px; }
.monthbar button, .iconbtn { min-width: 44px; min-height: 44px; }
.card { padding: 20px; margin-bottom: 18px; }
h3 { font-size: 1rem; letter-spacing: -.02em; }
.money { background: linear-gradient(135deg, var(--accent-soft), var(--card) 80%); border-color: color-mix(in srgb, var(--accent) 25%, var(--line)); }
.moneyhead { align-items: flex-start; flex-direction: column; gap: 0; margin-bottom: 18px; }
.moneyhead h3 { color: var(--muted); font-size: .86rem; margin-bottom: 4px; }
.moneyhead b { font-size: clamp(1.65rem, 7vw, 2.5rem); letter-spacing: -.045em; overflow-wrap: anywhere; max-width: 100%; }
.acclist li { min-height: 60px; padding: 12px 0; grid-template-columns: 32px minmax(0, 1fr) auto; }
.accname { overflow-wrap: anywhere; }
.acclist b { overflow-wrap: anywhere; }
.btn, .linkbtn, .seg button { min-height: 48px; }
.btn { border-radius: 14px; padding: 12px 16px; }
input:not([type=checkbox]), select, textarea { min-height: 50px; border-radius: 14px; }
.form label { gap: 7px; margin-bottom: 18px; font-weight: 500; }
.seg { padding: 4px; border-radius: 16px; gap: 2px; }
.seg button { border-radius: 12px; padding: 8px 6px; }
.tabs { padding-left: 6px; padding-right: 6px; }
.tabs button { gap: 5px; font-size: .64rem; min-width: 0; border-radius: 16px; margin: 6px 0; }
.tabs button.active { background: var(--accent-soft); }
.tabs button span { font-size: 1.3rem; }
.txlist li { min-height: 76px; grid-template-columns: 6px minmax(0, 1fr) auto; gap: 10px; padding: 14px; }
.txlist li > div { min-width: 0; overflow-wrap: anywhere; }
.txlist small { margin-top: 4px; }
.legend { min-width: 0; width: 100%; }
.legend li { grid-template-columns: 10px minmax(0, 1fr) auto 34px; font-size: .8rem; }
.legend li > span { overflow-wrap: anywhere; }
.fab { border-radius: 20px; width: auto; min-width: 60px; height: 56px; padding: 0 18px; display: flex; gap: 8px; align-items: center; justify-content: center; }
.fab::after { content: 'Agregar'; font-size: .9rem; font-weight: 700; }
#view { padding-bottom: 88px; }
.gate { background: radial-gradient(ellipse at top, var(--accent-soft), var(--bg) 65%); }
.gatebox { max-width: 400px; }
.gatelogo { width: 80px; height: 80px; border-radius: 24px; margin-bottom: 16px; }
.gate h1 { font-size: 2rem; font-weight: 800; letter-spacing: -.05em; }
.gatesub { margin-bottom: 20px; }
@media (max-width: 599px) {
  .cards3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
  .cards3 .card { padding: 16px; min-width: 0; }
  .cards3 .card:last-child { grid-column: 1 / -1; }
  .stat b { font-size: clamp(1rem, 4.5vw, 1.4rem); white-space: normal; overflow-wrap: anywhere; overflow: visible; }
  .stat small { margin-bottom: 6px; }
  .weekgrid { grid-template-columns: 1fr; gap: 0; }
  .weekgrid > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .weekgrid b { white-space: normal; overflow-wrap: anywhere; text-align: right; font-size: 1rem; }
  .money .row-end { display: grid; grid-template-columns: 1fr 1fr; }
  .money .row-end .btn { padding-left: 8px; padding-right: 8px; font-size: .85rem; }
  .btngrid { grid-template-columns: 1fr; }
  dialog:not(.ask) { width: 100%; max-width: 100%; max-height: calc(100dvh - env(safe-area-inset-top) - 16px); margin: auto 0 0; border-radius: 26px 26px 0 0; padding: 24px 20px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  dialog .row-end { gap: 8px; }
  dialog .row-end .btn { flex: 1 1 auto; }
  .gate { align-items: safe center; }
}
@media (max-width: 359px) {
  .brand { font-size: 1rem; }
  .card { padding: 16px; }
  .acclist li { grid-template-columns: 28px minmax(0, 1fr); }
  .acclist li > b { grid-column: 2; }
  .txlist li { grid-template-columns: 6px minmax(0, 1fr); }
  .txlist li > span { grid-column: 2; white-space: normal; overflow-wrap: anywhere; }
}
@media (min-width: 800px) {
  .tabs { top: calc(76px + env(safe-area-inset-top)); }
  .tabs button { margin: 0; font-size: .85rem; min-height: 48px; }
  .gatebox { padding: 32px; max-width: 460px; background: var(--card); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Navegación inferior también en computadores. */
@media (min-width: 800px) {
  body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
  .tabs {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-width: none; margin: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding: 6px max(16px, calc((100% - 760px) / 2)) calc(6px + env(safe-area-inset-bottom));
    border: 0; border-top: 1px solid var(--line); border-radius: 0; z-index: 6;
  }
  .tabs button { flex-direction: column; gap: 4px; font-size: .75rem; min-height: 48px; }
  .tabs button span { font-size: 1.3rem; }
  .fab { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px) !important; }
  .badge { position: absolute; top: 3px; left: calc(50% + 6px); margin-left: 0; }
}

/* Paleta y tipografía: azul índigo, superficies suaves y texto legible. */
:root, :root[data-theme="light"] {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #202b40;
  --muted: #59677e;
  --line: #dce3ee;
  --accent: #435dcc;
  --accent-soft: #e9edfc;
  --pos: #147348;
  --neg: #bb3939;
  --warn: #996400;
  --inc: #27946a;
  --exp: #d96756;
  --shadow: 0 4px 20px rgba(31, 48, 84, .045);
}
:root[data-theme="dark"] {
  --bg: #101622;
  --card: #1a2332;
  --text: #edf2fc;
  --muted: #acb9cf;
  --line: #303d52;
  --accent: #a2b5ff;
  --accent-soft: #263451;
  --pos: #73d9ac;
  --neg: #ff9b96;
  --warn: #efc76c;
  --inc: #73d9ac;
  --exp: #ff9b96;
  --shadow: 0 6px 24px rgba(0, 0, 0, .10);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}
h3, h4 { font-weight: 650; letter-spacing: -.015em; }
.brand { font-weight: 750; letter-spacing: -.025em; }
.moneyhead b { font-weight: 750; letter-spacing: -.035em; line-height: 1.2; }
.stat b, .weekgrid b { font-weight: 700; letter-spacing: -.02em; }
.stat small, .weekgrid small { font-size: .84rem; }
.form label, .flabel { font-size: .9rem; }
input, select, textarea { color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.btn, .fab { color: #fff; background: #435dcc; }
.btn.ghost, .btn.outline { color: var(--text); }
.btn.danger { color: var(--neg); }
.btn.dangerfill { background: #b93139; color: #fff; }
.btn.outline, .btn.ghost { background: var(--card); }
.tabs { box-shadow: 0 -4px 24px rgba(22, 35, 60, .06); }
.tabs button { font-weight: 500; }
.tabs button.active { color: var(--accent); font-weight: 700; }
.txlist small { font-size: .86rem; }
.money { background: linear-gradient(135deg, var(--accent-soft), var(--card)); }
@media (hover: hover) {
  .btn:hover, .fab:hover { filter: brightness(1.08); }
  .tabs button:hover { background: var(--accent-soft); }
}

@font-face {
  font-family: 'Manrope';
  src: url('manrope-variable.ttf') format('truetype');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
body { font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.brand, .gate h1 { font-weight: 800; }
.moneyhead b { font-weight: 800; }

.reserve-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 20px 0; }
.reserve-grid > div { padding: 16px; border-radius: 16px; background: var(--accent-soft); min-width: 0; }
.reserve-grid span { display: block; color: var(--muted); font-size: .85rem; }
.reserve-grid b { display: block; margin-top: 8px; font-size: 1.4rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.reserve-grid label { min-width: 0; margin: 0; }
@media (max-width: 359px) { .reserve-grid { grid-template-columns: 1fr; } }

.budget-repeat { display: flex; align-items: center; gap: 10px; min-height: 48px; margin-top: 8px; color: var(--muted); font-size: .9rem; }
.budget-repeat input { flex: none; accent-color: var(--accent); }

.summary-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.summary-head h3 { margin: 0; }
.summary-head a { color: var(--accent); font-size: .85rem; display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.summary-grid small { display: block; color: var(--muted); font-size: .8rem; }
.summary-grid b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.home-goals { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
@media (max-width: 420px) { .summary-grid { grid-template-columns: 1fr; } .summary-grid > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; } }

.budget-paid { color: var(--text); font-weight: 600; }
#budgetPayNotice { margin-bottom: 18px; }
#budgetPayAmount { font-size: 1.4rem; }

.budget-summary-title { margin: 0 4px 8px; }

.six-range { margin-bottom: 20px; }
.six-months .donut { width: 200px; height: 200px; }
.six-months .donut b { overflow-wrap: anywhere; max-width: 100%; }

/* Presupuesto cómodo de usar con una mano en pantallas pequeñas. */
.budget-panel > .row-end { margin: 18px 0; }
@media (max-width: 599px) {
  .budget-panel { background: transparent; border: 0; box-shadow: none; padding: 0; }
  .budget-panel > h3 { font-size: 1.2rem; margin: 0 4px 8px; }
  .budget-panel > .muted { margin: 0 4px; }
  .budget-panel > .row-end .btn { width: 100%; min-height: 52px; }
  .budget-items { display: grid; gap: 16px; }
  .budget-items .budrow { background: var(--card); padding: 18px; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
  .budget-items .budhead { flex-direction: column; gap: 4px; margin-bottom: 12px; }
  .budget-items .budhead > b { font-size: 1.05rem; overflow-wrap: anywhere; }
  .budget-items .budinput { display: block; margin: 16px 0; }
  .budget-items .budinput > label { display: block; margin-bottom: 7px; }
  .budget-items .budctl { display: grid; grid-template-columns: minmax(0, 1fr) 48px; gap: 10px; }
  .budget-items .budinput input { width: 100%; min-height: 52px; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
  .budget-items .iconbtn { width: 48px; height: 52px; border-radius: 14px; }
  .budget-items .budget-repeat { min-height: 56px; margin: 8px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; font-size: .9rem; line-height: 1.4; }
  .budget-items .budget-repeat input { width: 24px; height: 24px; }
  .budget-items .budget-paid { background: var(--accent-soft); border-color: transparent; }
  .budget-panel .empty { background: var(--card); border-radius: 20px; }
}

.budget-pay-all { padding: 16px; border-radius: 16px; background: var(--accent-soft); color: var(--text); font-weight: 700; margin-bottom: 16px; }
.bulk-budget-row { padding: 16px 0 0; margin-top: 16px; border-top: 1px solid var(--line); }
.bulk-budget-row > b { display: block; margin-bottom: 12px; overflow-wrap: anywhere; }
.edit-budget-payment { margin: 4px 0 8px; width: 100%; }

.tabs button[data-tab="movimientos"], .tabs button[data-tab="presupuesto"] { white-space: normal; text-align: center; }
@media (max-width: 799px) { .tabs button { font-size: .6rem; line-height: 1.2; padding: 4px 2px; } }

.occasional-total { font-size: 1.8rem; font-weight: 800; margin: 8px 0 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.occasional-details { margin-top: 14px; }
.occasional-details summary { min-height: 48px; padding: 12px 4px; cursor: pointer; color: var(--accent); font-weight: 600; }
.occasional-details .txlist { margin: 8px 0 16px; }

/* En teléfono, las leyendas van debajo del círculo sin comprimirse. */
@media (max-width: 599px) {
  .donutwrap { flex-direction: column; align-items: stretch; gap: 20px; }
  .donutwrap .donut { align-self: center; max-width: 100%; }
  .donutwrap .legend { flex: none; width: 100%; min-width: 0; }
  .donutwrap .legend li { grid-template-columns: 10px minmax(0, 1fr) auto 38px; gap: 8px; padding: 8px 0; }
  .donutwrap .legend b { font-size: .84rem; max-width: 38vw; overflow-wrap: anywhere; }
  .donutwrap .legend span { word-break: normal; }
}
