/* ============================================================
   Mis Apartados · estilos
   Lenguaje: iOS nativo (listas agrupadas, material translúcido,
   SF Pro / SF Rounded para cifras), un solo acento esmeralda.
   ============================================================ */

:root {
  --bg: #F2F2F7;
  --card: #FDFDFE;
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(118, 118, 128, .2);
  --press: rgba(60, 60, 67, .08);
  --ink: #111214;
  --ink-2: #5E6169;
  --ink-3: #7B7E86;
  --sep: rgba(60, 60, 67, .16);
  --accent: #0B7A53;
  --on-accent: #FDFDFE;
  --accent-tint: rgba(11, 122, 83, .12);
  --accent-ink: #066343;      /* texto verde sobre fondo verde claro */
  --ci-accent: #0B7A53;       /* relleno de íconos con acento: igual en ambos modos */
  --neg: #C9372C;
  --warn: #9A5B00;
  --warn-tint: rgba(255, 159, 10, .16);
  --mat: rgba(242, 242, 247, .78);
  --scrim: rgba(10, 10, 14, .4);
  --shadow: 0 10px 40px rgba(20, 24, 40, .14);

  --c-blue: #0A6CF0; --c-indigo: #5146D8; --c-purple: #9A48D0; --c-pink: #E0336E; --c-red: #E0372D;
  --c-orange: #D45F00; --c-yellow: #D9A100; --c-green: #23A04A; --c-teal: #0E98B4; --c-brown: #8E6A48; --c-gray: #8A8D95;

  --r-lg: 14px;   /* listas y tarjetas */
  --r-md: 12px;   /* botones e íconos grandes */
  --r-sm: 9px;    /* segmentos e íconos de fila */
  --tabh: 56px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --num: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0B0D;
    --card: #1B1B1F;
    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(118, 118, 128, .34);
    --press: rgba(255, 255, 255, .07);
    --ink: #F3F3F5;
    --ink-2: #A3A3AC;
    --ink-3: #7D7D86;
    --sep: rgba(255, 255, 255, .1);
    --accent: #34C98A;
    --on-accent: #06180F;
    --accent-tint: rgba(52, 201, 138, .15);
    --accent-ink: #6BE3AE;
    --neg: #FF6B5E;
    --warn: #FFB547;
    --warn-tint: rgba(255, 181, 71, .14);
    --mat: rgba(22, 22, 26, .74);
    --scrim: rgba(0, 0, 0, .48);
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
/* Con una hoja abierta, la página de fondo queda fija (iOS ignora overflow:hidden en body) */
body.locked { position: fixed; left: 0; right: 0; overflow: hidden; }
button { font: inherit; color: inherit; letter-spacing: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 600; }
input { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.ic { width: 22px; height: 22px; fill: currentColor; flex: none; display: block; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.neg { color: var(--neg) !important; }
.pos { color: var(--accent); }
.muted { color: var(--ink-2); }

#view {
  max-width: 600px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tabh) + env(safe-area-inset-bottom) + 32px);
}
#view[data-view="income"], #view[data-view="expense"] { padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 108px); }

/* ---------- Títulos ---------- */
.lt { padding: 10px 4px 18px; }
.lt h1 { margin: 0; font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; text-wrap: balance; }
.lt p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }

.navbar { height: 44px; display: flex; align-items: center; margin: 0 -8px; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px; color: var(--accent); font-size: 17px; }
.back .ic { width: 22px; height: 22px; }
.back:active { opacity: .5; }

/* ---------- Saldo principal ---------- */
/* Inicio: fecha pequeña en mayúsculas sobre el título grande (como Apple News / Salud) */
.home-lt { padding-bottom: 14px; }
.lt-date { margin: 0 0 2px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.balance { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 4px 4px 22px; border-radius: var(--r-lg); }
.balance-l { font-size: 15px; color: var(--ink-2); }
.balance-n { font-size: min(48px, 13vw); max-width: 100%; overflow-wrap: anywhere; line-height: 1.08; font-weight: 700; letter-spacing: -0.03em; margin: 2px 0 8px; font-family: var(--num); font-variant-numeric: tabular-nums; }
.balance-s { display: inline-flex; align-items: center; gap: 4px; font-size: 15px; color: var(--ink-2); }
.balance-s b { color: var(--ink); font-weight: 600; }
.balance-s .chev { width: 14px; height: 14px; color: var(--ink-3); }
.balance:active .balance-n { opacity: .6; }
.balance-n.long { font-size: min(40px, 10.5vw); }   /* cifras de 11+ caracteres */
.balance-n.xlong { font-size: min(34px, 8.8vw); }  /* cifras de 14+ caracteres */

/* ---------- Aviso de pasos pendientes ---------- */
.notice {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; margin-bottom: 16px;
  background: var(--warn-tint); color: var(--ink); border-radius: var(--r-lg);
  transition: transform .12s var(--ease);
}
.notice-ic { color: var(--warn); width: 26px; height: 26px; }
.notice .chev { color: var(--warn); }
.notice:active { transform: scale(.98); }

/* ---------- Botones ---------- */
.actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 28px; }
.actions .btn { font-size: 16px; gap: 6px; padding: 0 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 14px; border-radius: var(--r-md);
  font-size: 17px; font-weight: 600; white-space: nowrap; text-align: center;
  transition: transform .12s var(--ease), opacity .12s, background-color .2s;
}
.btn .ic { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.tinted { background: var(--accent-tint); color: var(--accent-ink); }
.btn.wide { width: 100%; }
.btn:active:not(:disabled) { transform: scale(.97); opacity: .9; }
.btn:disabled { background: var(--fill); color: var(--ink-3); }
.text-btn { color: var(--accent); font-size: 17px; min-height: 44px; padding: 0 4px; }
.text-btn.strong { font-weight: 650; }
.text-btn:active { opacity: .5; }

/* ---------- Grupos y listas ---------- */
.group { margin-bottom: 26px; }
.group-h {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  margin: 0 4px 8px; font-size: 15px; font-weight: 600; color: var(--ink-2); letter-spacing: -0.005em;
}
.group-h > span:first-child { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 17px; }
.group-h .num { font-weight: 600; }
.group-link { color: var(--accent-ink); font-size: 15px; font-weight: 500; min-height: 44px; margin: -8px 0; padding: 0 2px; display: inline-flex; align-items: center; }
.group-f { margin: 8px 4px 0; font-size: 13px; line-height: 1.4; color: var(--ink-2); }

.list { background: var(--card); border-radius: var(--r-lg); overflow: hidden; }
.list + .list { margin-top: 12px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
  transition: background-color .15s;
}
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 58px; border-top: .5px solid var(--sep); }
button.row:active, label.row:not(.static):active { background: var(--press); }
.row.static { cursor: default; }
.rt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.rt b {
  font-weight: 500; font-size: 17px; overflow: hidden; overflow-wrap: anywhere;
  /* nombres largos pasan a una segunda línea en vez de cortarse (máximo dos) */
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.25;
}
.rt small { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ra { font-size: 17px; font-weight: 600; white-space: nowrap; }
.chev { width: 16px; height: 16px; color: var(--ink-3); margin-right: -4px; }
.row.add { color: var(--accent); }
.row.add .ic { width: 30px; height: 30px; padding: 5px; }
.row.add .rt b { font-weight: 500; }
.row.destructive { color: var(--neg); justify-content: center; }
.row.destructive .rt { flex: none; }
.row.total .rt b { font-weight: 600; }
.row.total .ra { color: var(--accent); font-size: 20px; }
.row.total::before { left: 14px !important; }

/* Icono de apartado */
.ci {
  width: 30px; height: 30px; border-radius: var(--r-sm); flex: none;
  display: grid; place-items: center; background: var(--cc); color: #FDFDFE;
}
.ci .ic { width: 18px; height: 18px; }
.ci[data-c="yellow"], .icons[data-c="yellow"] .ib.on { color: #3A2B00; } /* blanco sobre amarillo no se lee */
.ci.xl { width: 64px; height: 64px; border-radius: 18px; }
.ci.xl .ic { width: 36px; height: 36px; }

/* ---------- Formularios ---------- */
.form .row, .amount-row { min-height: 56px; }
.amount-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: text; }
.amount-row + .amount-row::before, .amount-row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 58px; border-top: .5px solid var(--sep); }
.amt-in { display: flex; align-items: baseline; justify-content: flex-end; gap: 2px; max-width: 60%; min-width: 0; flex: none; }
.amt-in .cur { font-family: var(--num); font-size: 22px; font-weight: 600; color: var(--ink-3); flex: none; }
.amt-in.pct .cur { order: 2; margin-left: 2px; } /* "10 %": el porcentaje va después del número */
.amount-row .rt { min-width: 0; }
.amt-in input {
  width: 2.4ch; min-width: 0; max-width: 100%; border: 0; outline: 0; background: transparent; padding: 0;
  font-size: 26px; font-weight: 650; text-align: right;
}
.amt-in input::placeholder, .amount-hero input::placeholder { color: var(--ink-3); opacity: .55; }
.date-in {
  border: 0; outline: 0; background: var(--fill); border-radius: 8px; padding: 6px 10px;
  font-size: 17px; color: var(--ink); min-height: 34px; -webkit-appearance: none; appearance: none;
  flex: 0 1 auto; width: auto; min-width: 0; max-width: 62%; /* deja espacio a la etiqueta "Fecha" */
}
.row:has(.date-in) .rt { flex: 1 0 auto; }
.date-in::-webkit-date-and-time-value { text-align: right; }
.text-in { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 6px 0; font-size: 17px; }
.text-in::placeholder { color: var(--ink-3); }
.text-in.center { text-align: center; font-size: 20px; font-weight: 600; }

.chip-btn {
  display: flex; align-items: center; gap: 8px; margin: 12px auto 0; padding: 9px 14px;
  border-radius: 999px; background: var(--accent-tint); color: var(--accent); font-size: 15px; font-weight: 600;
  transition: transform .12s var(--ease);
}
.chip-btn .ic { width: 17px; height: 17px; }
.chip-btn:active { transform: scale(.97); }
#preview { margin-top: 26px; }

.seg { display: flex; background: var(--fill); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button {
  flex: 1; text-align: center; min-height: 40px; border-radius: 7px;
  font-size: 15px; font-weight: 500; color: var(--ink);
  transition: background-color .2s var(--ease), box-shadow .2s;
}
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }
@media (prefers-color-scheme: dark) { .seg button.on { background: #636366; } }

/* Barra fija de acción (encima de las pestañas) */
.cta-bar {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding: 10px 16px 10px;
  background: var(--mat);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  view-transition-name: cta;
}
.cta-bar .btn { max-width: 568px; margin: 0 auto; display: flex; }

/* ---------- Plan de reparto ---------- */
.plan-head { background: var(--card); border-radius: var(--r-lg); padding: 14px; margin-bottom: 16px; }
.ph-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ph-cols > div { display: flex; flex-direction: column; min-width: 0; }
.lbl { font-size: 13px; color: var(--ink-2); }
.ph-cols b { font-size: 19px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ph-cols .hl b { color: var(--accent); }
.dist { display: flex; gap: 2px; height: 10px; margin-top: 12px; border-radius: 5px; overflow: hidden; }
.dist span { min-width: 3px; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 20px; border-radius: var(--r-lg); background: var(--warn-tint); font-size: 15px; }
.alert .ic { color: var(--warn); margin-top: 1px; }
.alert p { margin: 0; }

.step-n {
  width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 700; font-family: var(--num);
}
.step-n.accent { background: var(--accent); color: var(--on-accent); }

.check {
  width: 24px; height: 24px; border-radius: 50%; flex: none; display: grid; place-items: center;
  border: 1.5px solid var(--ink-3); color: transparent;
  transition: background-color .18s var(--ease), border-color .18s, transform .18s var(--ease);
}
.check .ic { width: 15px; height: 15px; }
.step.done .check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); transform: scale(1.04); }
.step.done .rt b, .step.done .ra { color: var(--ink-3); }
.step.done .rt b { text-decoration: line-through; text-decoration-color: var(--ink-3); }
.step.done .ci { opacity: .45; }
.list .step .rt small { white-space: normal; }
.step:has(.check) + .step::before { left: 94px; }

.progress-wrap { margin: -6px 4px 22px; }
.progress { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transform-origin: left; transition: transform .35s var(--ease); }
.progress-wrap p { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 13px; color: var(--ink-2); }
.progress-wrap p .ic { width: 15px; height: 15px; color: var(--accent); }

/* ---------- Registrar gasto ---------- */
.amount-hero { display: flex; justify-content: center; align-items: baseline; gap: 4px; margin: 26px 0 4px; cursor: text; }
.amount-hero .cur { font-family: var(--num); font-size: 34px; font-weight: 600; color: var(--ink-3); }
.amount-hero input {
  border: 0; outline: 0; background: transparent; padding: 0; text-align: center;
  font-size: 56px; font-weight: 700; letter-spacing: -0.03em; width: 1.4ch; min-width: 0; max-width: 80vw;
}
.after { text-align: center; margin: 0 0 26px; font-size: 15px; color: var(--ink-2); min-height: 21px; }
.after b { color: var(--ink); font-weight: 600; }

.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
/* Cuadro de apartado: nombre arriba (hasta 2 líneas); ícono y monto comparten el renglón de abajo */
.tile {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 11px 12px; background: var(--card); border-radius: var(--r-lg); text-align: left;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .18s var(--ease), transform .12s var(--ease);
}
.tile b {
  font-weight: 600; font-size: 15px; line-height: 1.25; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.tile-foot .ci { width: 28px; height: 28px; }
.tile-foot small { font-size: 15px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tile.on { box-shadow: inset 0 0 0 2px var(--accent); }
.tile:active { transform: scale(.97); }

/* ---------- Historial ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; margin: -8px -16px 18px; padding: 6px 16px; scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; scroll-snap-align: start;
  position: relative; min-height: 36px; padding: 0 13px; border-radius: 999px; background: var(--card);
  font-size: 15px; font-weight: 500; white-space: nowrap;
  transition: background-color .18s, color .18s, transform .12s var(--ease);
}
.chip::after { content: ""; position: absolute; inset: -4px 0; } /* zona táctil de 44pt */
.chip .ic { width: 16px; height: 16px; color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--bg); }
.chip.on .ic { color: var(--bg); }
.chip:active { transform: scale(.96); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 24px; color: var(--ink-2); }
.empty-ic { width: 40px; height: 40px; color: var(--ink-3); margin-bottom: 12px; }
.empty b { color: var(--ink); font-size: 17px; font-weight: 600; }
.empty p { margin: 4px 0 0; font-size: 15px; max-width: 30ch; }

.onboard { padding: 16px; }
.onboard b { font-weight: 600; }
.onboard ol { margin: 8px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 15px; line-height: 1.5; }
.onboard li { padding: 2px 0; }
.onboard li b { color: var(--ink); }

/* ---------- Detalle de apartado ---------- */
.cat-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8px 0 20px; }
.cat-head h1 { margin: 12px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.cat-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.cat-head .balance-n { margin: 14px 0 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: var(--r-lg); margin-bottom: 14px; }
.stats > div { display: flex; flex-direction: column; padding: 12px 14px; min-width: 0; }
.stats > div + div { border-left: .5px solid var(--sep); }
.stats b { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Ajustes ---------- */
.ord { display: flex; gap: 4px; }
.ord button { width: 44px; height: 44px; display: grid; place-items: center; color: var(--accent); border-radius: 10px; }
.ord button:active { background: var(--press); }
.ord button:disabled { color: var(--ink-3); opacity: .4; }

/* ---------- Hoja inferior ---------- */
#sheetLayer { position: fixed; inset: 0; z-index: 30; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 600px;
  max-height: calc(100% - env(safe-area-inset-top) - 12px); /* 100% del área visible, aun con teclado */
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
  will-change: transform; touch-action: none; outline: none;
}
.sheet-grab { display: grid; place-items: center; height: 30px; flex: none; cursor: grab; }
.sheet-grab span { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px calc(env(safe-area-inset-bottom) + 20px); touch-action: pan-y; }

.sheet-bar { display: flex; align-items: center; justify-content: space-between; margin: -4px -4px 4px; }
.sheet-bar b { font-size: 17px; font-weight: 600; }
.cat-preview { display: grid; place-items: center; padding: 10px 0 16px; }
.cat-form .list { margin-bottom: 6px; }
.cat-form .seg + .list { margin-top: 10px; }
.field-l { font-size: 13px; color: var(--ink-2); margin: 18px 4px 8px; }
.err { margin: 6px 4px 0; font-size: 13px; color: var(--neg); }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 10px; background: var(--card); border-radius: var(--r-lg); padding: 14px; }
.sw { aspect-ratio: 1; border-radius: 50%; background: var(--cc); box-shadow: 0 0 0 0 var(--bg), 0 0 0 0 var(--cc); transition: box-shadow .18s var(--ease); min-width: 44px; }
.sw.on { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--cc); }
.icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; background: var(--card); border-radius: var(--r-lg); padding: 10px; margin-bottom: 22px; }
.ib { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; color: var(--ink-2); transition: background-color .15s, color .15s; }
.ib .ic { width: 22px; height: 22px; }
.ib.on { background: var(--cc, var(--accent)); color: #FDFDFE; }
.ib:active { background: var(--press); }

.as { padding-top: 4px; }
.as-head { text-align: center; padding: 6px 12px 16px; }
.as-head b { font-size: 17px; font-weight: 600; }
.as-head p { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.as-btn { justify-content: center; font-size: 17px; color: var(--accent); }
.as-btn + .as-btn::before { left: 0 !important; }
.as-btn.cancel { font-weight: 600; }

/* ---------- Aviso ---------- */
#toast {
  position: fixed; left: 50%; z-index: 40;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 14px);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: var(--r-lg);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  font-size: 15px; font-weight: 500;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: transform .3s var(--ease), opacity .2s;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
#toast.has-undo {
  overflow: hidden; padding-bottom: 15px;
  width: min(360px, calc(100vw - 32px)); justify-content: space-between;
}
#toast > span:first-child { flex: 1; min-width: 0; }
.toast-bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: var(--toast-accent); transform-origin: left;
  animation: toast-fill linear forwards;
}
@keyframes toast-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* El aviso es oscuro en modo claro y claro en modo oscuro: su acento se invierte para mantener contraste */
#toast { --toast-accent: #5EE0A8; }
@media (prefers-color-scheme: dark) { #toast { --toast-accent: #0B7A53; } }
#toast button { color: var(--toast-accent); font-weight: 650; min-height: 44px; padding: 0 4px; margin: -6px -4px; white-space: nowrap; }
#view[data-view="income"] ~ #toast, #view[data-view="expense"] ~ #toast { bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 84px); }

/* ---------- Barra de pestañas ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 0 4px env(safe-area-inset-bottom);
  background: var(--mat);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep);
  view-transition-name: tabs;
}
.tab {
  flex: 1; max-width: 120px; height: var(--tabh);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); font-size: 11px; font-weight: 500; letter-spacing: 0;
}
.tab .ic { width: 26px; height: 26px; }
.tab.on { color: var(--accent); }
.tab:active .ic-wrap { transform: scale(.88); }
.ic-wrap { transition: transform .12s var(--ease); }

/* ---------- Transiciones entre pantallas ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .32s; animation-timing-function: var(--ease); }
html[data-nav="push"]::view-transition-old(root) { animation-name: vt-out-left; }
html[data-nav="push"]::view-transition-new(root) { animation-name: vt-in-right; }
html[data-nav="pop"]::view-transition-old(root) { animation-name: vt-out-right; }
html[data-nav="pop"]::view-transition-new(root) { animation-name: vt-in-left; }
html[data-nav="fade"]::view-transition-old(root), html[data-nav="fade"]::view-transition-new(root) { animation-duration: .18s; }
::view-transition-group(tabs), ::view-transition-group(cta) { animation: none; }
@keyframes vt-in-right { from { transform: translateX(32%); opacity: 0; } }
@keyframes vt-out-left { to { transform: translateX(-12%); opacity: 0; } }
@keyframes vt-in-left { from { transform: translateX(-12%); opacity: 0; } }
@keyframes vt-out-right { to { transform: translateX(32%); opacity: 0; } }

/* ---------- Accesibilidad ---------- */
@media (prefers-reduced-motion: reduce) {
  *:not(.toast-bar), *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
  /* la barra de "Deshacer" se queda: comunica cuánto tiempo queda, no es movimiento decorativo */
}
@media (prefers-reduced-transparency: reduce) {
  #tabs, .cta-bar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --ink-2: var(--ink); --sep: var(--ink-3); }
}
@media (min-width: 700px) {
  .lt h1 { font-size: 40px; }
}

/* ---------- Respaldo en la nube ---------- */
.notice.key { background: var(--accent-tint); }
.notice.key .notice-ic, .notice.key .chev { color: var(--accent); }
.spacer { width: 64px; }
.sheet-p { margin: 4px 4px 16px; font-size: 15px; color: var(--ink-2); text-align: center; }
.key-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 6px 8px 18px; }
.key-hero p { margin: 0; font-size: 15px; color: var(--ink-2); max-width: 34ch; }
.key-box {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 12px; margin-bottom: 14px; background: var(--card); border-radius: var(--r-lg);
  font: 600 22px/1.3 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em;
  user-select: all; -webkit-user-select: all;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .04em; font-size: 16px !important; }
.key-sheet .actions { margin-bottom: 4px; }
.key-sheet .btn.wide { margin-top: 6px; }

/* ---------- Deslizar para eliminar (Ajustes) ---------- */
.swipe { position: relative; overflow: hidden; }
.swipe + .swipe::before, .swipe + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: 58px; z-index: 2;
  border-top: .5px solid var(--sep); pointer-events: none;
}
.swipe-fg { position: relative; z-index: 1; background: var(--card); touch-action: pan-y; will-change: transform; }
/* Al presionar, el fondo sigue siendo sólido (el resaltado va encima) para que nunca se vea el rojo a través */
button.row.swipe-fg:active { background: var(--card); box-shadow: inset 0 0 0 100vmax var(--press); }
.swipe-del {
  position: absolute; top: 0; bottom: 0; right: 0; width: 0; overflow: hidden;
  display: flex; justify-content: flex-end; align-items: stretch;
  background: #C9281F; color: #FDFDFE; /* rojo de iOS, con contraste suficiente para texto blanco */
}
.swipe-del > span {
  width: 88px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 600;
}
.swipe-del .ic { width: 22px; height: 22px; }
.swipe:not(.moving) .swipe-del { visibility: hidden; }

/* ============================================================
   Historial: búsqueda y Reportes
   ============================================================ */
:root { --series-bnx: #0A6CF0; --series-cash: #0B7A53; } /* validados: claro */
@media (prefers-color-scheme: dark) { :root { --series-bnx: #3D8BFF; --series-cash: #22A86E; } } /* validados: oscuro */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hist-seg { margin-bottom: 14px; }

/* Buscar */
.search { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 6px 0 12px; margin-bottom: 12px; background: var(--fill); border-radius: var(--r-md); color: var(--ink-2); cursor: text; }
.search .ic { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; color: var(--ink); -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-cancel-button { display: none; }
.search input::placeholder { color: var(--ink-3); }
.search-x { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink-3); }
.search-sum { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; margin-bottom: 22px; background: var(--card); border-radius: var(--r-lg); }
.search-sum b { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.search-sum small { color: var(--ink-2); font-size: 13px; }

/* Bloques de reporte */
.rep { padding: 4px 16px 6px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px; }
.month-nav b { font-size: 15px; font-weight: 600; }
.month-nav button { width: 44px; height: 44px; display: grid; place-items: center; color: var(--accent-ink); border-radius: 10px; }
.month-nav button:disabled { color: var(--ink-3); opacity: .4; }
.month-nav button:active:not(:disabled) { background: var(--press); }
.rep-head { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 12px; border-bottom: .5px solid var(--sep); }
.rep-big { font-size: 34px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; }
.delta { display: inline-flex; align-items: center; gap: 2px; color: var(--ink-2); font-size: 13px; }
.delta-ic { width: 13px; height: 13px; display: inline-block; vertical-align: -2px; }
.rep-empty { margin: 0; padding: 18px 0; color: var(--ink-2); font-size: 15px; text-align: center; }

.rep-row, .goal { display: flex; flex-direction: column; gap: 7px; width: 100%; padding: 12px 0; text-align: left; }
.rep-row + .rep-row { border-top: .5px solid var(--sep); }
.rep-row:active, .goal:active, .period:active { opacity: .7; }
.rep-top { display: flex; align-items: center; gap: 10px; }
.rep-top .ci { width: 26px; height: 26px; border-radius: 8px; }
.rep-top .ci .ic { width: 16px; height: 16px; }
.rep-top b { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rep-top .num { font-size: 15px; font-weight: 600; }
.rep-row small, .goal small { font-size: 13px; color: var(--ink-2); line-height: 1.35; }
.hbar { position: relative; height: 8px; border-radius: 4px; background: var(--fill); }
.hfill { position: absolute; inset: 0; border-radius: 4px; transform-origin: left; }
.tick { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--ink); box-shadow: 0 0 0 2px var(--card); }
.warn-t, .ok-t { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.warn-t { color: var(--warn); }
.ok-t { color: var(--accent-ink); }
.warn-t .ic, .ok-t .ic { width: 15px; height: 15px; }

/* Metas */
.goals { display: grid; gap: 10px; margin-bottom: 10px; }
.goal { background: var(--card); border-radius: var(--r-lg); padding: 14px 16px; }
.goal .lbl { font-weight: 600; }
.goal-amt { font-size: 15px; color: var(--ink-2); }
.goal-amt b { font-size: 24px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; }
.spark { width: 100%; height: 44px; display: block; overflow: visible; }
.spark-goal { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.add-goal { display: inline-flex; align-items: center; gap: 4px; color: var(--accent-ink); font-size: 15px; font-weight: 500; white-space: nowrap; }
.add-goal .ic { width: 17px; height: 17px; }

/* Cada catorcena */
.periods { display: grid; gap: 10px; }
.period { display: block; width: 100%; padding: 12px 16px 14px; background: var(--card); border-radius: var(--r-lg); text-align: left; }
.period-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.period-h b { flex: 1; font-size: 15px; font-weight: 600; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-tint); color: var(--accent-ink); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.kpis > span { display: flex; flex-direction: column; min-width: 0; }
.kpis small { font-size: 12px; color: var(--ink-2); }
.kpis b { font-size: 17px; font-weight: 650; white-space: nowrap; }
.kpis em { font-style: normal; font-size: 12px; color: var(--ink-2); }
.more-btn { display: block; margin: 6px auto 0; }

/* Ingresos */
.inc-cap { margin: 10px 0 4px; font-size: 13px; min-height: 18px; }
.inc-cap .muted { color: var(--ink-2); }
.vchart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 6px; }
.vbar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.vstack { width: 100%; max-width: 30px; display: flex; flex-direction: column; gap: 2px; border-radius: 4px 4px 0 0; overflow: hidden; opacity: .55; transition: opacity .15s; }
.vbar.on .vstack, .vbar:active .vstack { opacity: 1; }
.vstack > span { min-height: 2px; }
.vbar small { font-size: 10px; color: var(--ink-2); white-space: nowrap; }
.seg-bnx { background: var(--series-bnx); }
.seg-cash { background: var(--series-cash); }
.legend { display: flex; gap: 16px; padding: 10px 0 2px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.foot-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 10px; padding: 10px 0 8px; border-top: .5px solid var(--sep); }
.foot-stats > span { display: flex; flex-direction: column; min-width: 0; }
.foot-stats small { font-size: 12px; color: var(--ink-2); }
.foot-stats b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Filtro de apartado en Historial: un chip que abre una hoja */
.chip .caret { width: 13px; height: 13px; color: currentColor; margin-right: -3px; }
.chip-pick { padding: 0; gap: 0; flex: none; max-width: 72vw; }
.chip-pick .chip-main { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 2px 0 13px; min-width: 0; color: inherit; }
.chip-pick .chip-main .ic { flex: none; }
.chip-pick .chip-t { overflow: hidden; text-overflow: ellipsis; }
.chip-pick .chip-x { display: inline-grid; place-items: center; width: 36px; min-height: 36px; color: inherit; }
.chip-pick .chip-x .ic { width: 15px; height: 15px; color: var(--bg); opacity: .75; }
.pick-sheet .group:last-child { margin-bottom: 8px; }
.pick-check { color: var(--accent); display: inline-flex; }
.pick-check .ic { width: 20px; height: 20px; }
.sheet-bar > span:first-child { width: 52px; }
/* La zona táctil ampliada del chip no debe tapar sus dos botones internos */
.chip-pick > button { position: relative; z-index: 1; }
.chip-pick > button::after { content: ""; position: absolute; inset: -4px 0; }

/* Pago: indicación justo debajo de los campos, antes de la lista de apartados */
.preview-hint { margin: 2px 4px 22px; font-size: 15px; line-height: 1.4; color: var(--ink-2); }

/* ============================================================
   Recorrido de bienvenida
   ============================================================ */
#tour { position: fixed; inset: 0; z-index: 60; touch-action: none; -webkit-user-select: none; user-select: none; }
.tour-spot {
  position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none;
  box-shadow: 0 0 0 200vmax rgba(8, 10, 18, .62);
  opacity: 0; transition: opacity .35s var(--ease);
  will-change: transform, width, height;
}
#tour.on .tour-spot { opacity: 1; }
#tour.leaving .tour-spot { opacity: 0; transition-duration: .28s; }
@media (prefers-color-scheme: dark) { .tour-spot { box-shadow: 0 0 0 200vmax rgba(0, 0, 0, .74); } }
/* Destello al llegar: un anillo que se expande y se desvanece */
.tour-spot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 2px rgba(255, 255, 255, .9); opacity: 0; }
.tour-spot.pulse::after { animation: tour-ring 1.1s var(--ease) 2; }
@keyframes tour-ring { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.08); } }

.tour-card {
  position: fixed; padding: 18px 18px 16px; border-radius: 22px;
  background: var(--card); color: var(--ink); box-shadow: 0 18px 60px rgba(0, 0, 0, .35);
  opacity: 0; transform: translateY(var(--ty, 10px)) scale(.96); transform-origin: var(--ax, 50%) var(--oy, 0%);
  transition: opacity .2s var(--ease), transform .45s cubic-bezier(.22, 1, .36, 1);
  pointer-events: none;
}
.tour-card[data-side="above"] { --ty: -10px; --oy: 100%; }
.tour-card[data-side="center"] { --ty: 16px; --oy: 50%; --ax: 50%; padding: 26px 22px 18px; border-radius: 28px; }
.tour-card.show { opacity: 1; transform: none; pointer-events: auto; }
#tour.leaving .tour-card { opacity: 0; transform: scale(.96); transition-duration: .2s; }
.tour-arrow {
  position: absolute; left: calc(var(--ax) - 9px); width: 18px; height: 18px; background: var(--card);
  border-radius: 4px; transform: rotate(45deg);
}
.tour-card[data-side="below"] .tour-arrow { top: -7px; }
.tour-card[data-side="above"] .tour-arrow { bottom: -7px; }

.tour-top { display: flex; align-items: center; justify-content: space-between; margin: -10px -6px 2px 0; }
.tour-n { font-size: 13px; font-weight: 600; color: var(--accent-ink); letter-spacing: .01em; }
.text-btn.small { font-size: 15px; color: var(--ink-2); }
.tour-t { margin: 0 0 6px; font-size: 21px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; text-wrap: balance; }
.tour-p { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink-2); text-wrap: pretty; }
.tour-t.center, .tour-p.center { text-align: center; }
.tour-foot { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.tour-bar { flex: 1; height: 4px; border-radius: 4px; background: var(--sep); overflow: hidden; }
.tour-bar i { display: block; height: 100%; width: 100%; border-radius: inherit; background: var(--accent); transform-origin: left; transform: scaleX(var(--p)); transition: transform .5s var(--ease); }
.tour-back { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--fill, rgba(120, 120, 128, .14)); color: var(--ink); }
.tour-back .ic { width: 20px; height: 20px; }
.tour-back:active { transform: scale(.94); }
.tour-next { min-width: 118px; height: 44px; padding: 0 18px; }
.tour-hero { display: grid; place-items: center; margin-bottom: 14px; }
.tour-hero img { width: 72px; height: 72px; border-radius: 17px; box-shadow: 0 8px 24px rgba(0, 0, 0, .22); }
.tour-hero.done .ic { width: 64px; height: 64px; color: var(--accent); }
.tour-stack { display: grid; gap: 4px; margin-top: 20px; justify-items: center; }
.tour-stack .btn { width: 100%; }

/* Al cambiar de pantalla durante el recorrido, el contenido aparece con un fundido */
#view.tour-swap { animation: tour-fade .32s var(--ease); }
@keyframes tour-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .tour-card { transform: none !important; transition: opacity .2s; }
  #view.tour-swap { animation: none; }
}
.tour-card button:focus:not(:focus-visible) { outline: none; }

/* ---------- Pagos mensuales y recordatorios ---------- */
/* Interruptor estilo iOS */
.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; margin: 0;
  width: 51px; height: 31px; border-radius: 31px; background: var(--fill-2);
  transition: background-color .25s var(--ease); cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16);
  transition: transform .3s cubic-bezier(.22, 1, .36, 1);
}
.switch:checked { background: #34C759; }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Selector nativo (en iPhone abre la rueda del sistema) */
.sel {
  appearance: none; -webkit-appearance: none; border: 0; background: var(--fill); color: var(--ink);
  font: inherit; font-size: 16px; font-weight: 500; min-height: 36px; padding: 0 30px 0 12px; border-radius: 10px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.due-opt[hidden] { display: none !important; }
#dueBox + .group-f { margin: 8px 4px 4px; }
#dueBox .row + .row::before { left: 16px; }
.due-line { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; margin-top: 4px !important; }
.due-line .ic { width: 15px; height: 15px; }

/* Aviso de pago próximo en Inicio: dos zonas, abrir el apartado o marcarlo pagado */
.notice.due { padding: 0; gap: 0; overflow: hidden; }
.notice.due:active { transform: none; }
.notice-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 6px 12px 14px; text-align: left; color: inherit; }
.notice-main:active { opacity: .6; }
.notice-btn {
  flex: none; margin-right: 10px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  background: var(--card); color: var(--ink); font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
.notice-btn::after { content: ""; position: absolute; inset: -4px -2px; }
.notice-btn { position: relative; }
.notice-btn:active { transform: scale(.96); }
.notice.due.late { background: var(--neg-tint, rgba(255, 59, 48, .12)); }
.notice.due.late .notice-ic { color: var(--neg); }

.row-state { flex: none; font-size: 15px; color: var(--accent-ink); font-weight: 500; }
.row-state.on { color: var(--ink-3); font-weight: 400; }
