/* =========================================================================
   MisGastos — hoja de estilos única.
   Los tokens reproducen literalmente los del prototipo `App Móvil.dc.html`.
   Móvil primero; el escritorio es adaptación secundaria.
   ========================================================================= */

:root {
  /* Color base */
  --bg:            oklch(98% 0.004 250);
  --surface:       #ffffff;
  --surface-2:     oklch(96% 0.004 250);
  --neutral:       oklch(94% 0.006 250);
  --border:        oklch(93% 0.006 250);
  --border-strong: oklch(88% 0.01 250);
  --text:          oklch(20% 0.02 250);
  --text-strong:   oklch(18% 0.02 250);
  --muted:         oklch(48% 0.015 250);
  --muted-2:       oklch(55% 0.015 250);
  --muted-3:       oklch(60% 0.015 250);
  --accent:        oklch(52% 0.09 190);
  --accent-soft:   oklch(85% 0.06 190);
  --accent-dark:   oklch(42% 0.08 190);
  --income:        oklch(50% 0.11 150);
  --danger:        oklch(55% 0.16 30);
  --warn-bg:       oklch(97% 0.03 70);
  --warn-border:   oklch(88% 0.02 60);
  --warn-icon:     oklch(55% 0.14 55);
  --warn-title:    oklch(30% 0.05 55);
  --warn-text:     oklch(45% 0.03 55);

  /* Radios */
  --r-card:   20px;
  --r-card-s: 16px;
  --r-tile:   10px;
  --r-input:  12px;
  --r-chip:   20px;
  --r-btn:    14px;

  /* Espaciado lateral constante del prototipo */
  --pad: 24px;

  /* Áreas seguras del dispositivo */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  /* Altura de la barra inferior (incluye área segura) */
  --tabbar-h: calc(68px + var(--safe-bottom));

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* min-height, no height: con la altura fija el contenido que se pasaba de la
     pantalla se recortaba en vez de poder desplazarse. */
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Nada depende de hover ni de gestos: sólo evita el destello azul del tap. */
* { -webkit-tap-highlight-color: transparent; }

/* ------------------------------------------- comportarse como una aplicación

   La app está instalada en la pantalla de inicio y se usa a una mano, así que
   se quitan tres gestos del navegador que aquí sólo estorban:

   1. `touch-action: manipulation` desaparece el DOBLE TOQUE que amplía. Es lo
      único que funciona en Safari de iOS: `user-scalable=no` en el viewport lo
      ignora desde iOS 10 por accesibilidad, así que no basta con el meta.
   2. Sin selección de texto: al mantener el dedo sobre un importe salía la lupa
      y el menú de copiar en vez de responder al toque. Los campos donde SÍ hay
      que poder seleccionar y copiar se reactivan más abajo, uno a uno.
   3. Sin desplazamiento horizontal: la app es de una sola columna; si algo se
      desborda, se corrige el elemento, no se arrastra la pantalla.

   El zoom con dos dedos sigue disponible: no se le quita a nadie la posibilidad
   de ampliar si lo necesita. */
html, body {
  touch-action: manipulation;
  /* `hidden` convierte el elemento en contenedor de scroll, y eso rompe el
     arrastre tactil en algunos navegadores de escritorio. `clip` recorta igual
     sin crear contenedor; donde no exista, se queda con `hidden`. */
  overflow-x: hidden;
  overflow-x: clip;
  max-width: 100%;
}
body {
  -webkit-user-select: none;
  user-select: none;
}

/* ...pero en un ESCRITORIO no. Ahí el puntero principal es el ratón (Chrome en
   Windows, aunque la pantalla sea táctil) y esas tres restricciones sobran: el
   navegador ya trae su propio comportamiento y quitárselas impedía arrastrar
   con el dedo para desplazar la página. En el móvil esta regla no se aplica. */
@media (pointer: fine) {
  html, body { touch-action: auto; }
  body { -webkit-user-select: text; user-select: text; }
  /* Y que arrastrar sobre una fila —casi todas son enlaces— desplace en vez de
     arrancar el arrastre nativo del enlace o de la imagen. */
  a, img { -webkit-user-drag: none; user-drag: none; }
}

/* Donde el texto sí se selecciona: al escribir y al copiar. */
input, textarea, select, [contenteditable], [data-select-all], .selectable, code, pre {
  -webkit-user-select: text;
  user-select: text;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ------------------------------------------------------------------ marco */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

@media (min-width: 900px) {
  body { background: oklch(94% 0.005 250); }
  .app {
    max-width: 430px;
    min-height: 100dvh;
    box-shadow: 0 0 0 1px var(--border), 0 20px 60px rgba(0,0,0,.08);
  }
}

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-bottom: calc(var(--tabbar-h) + 8px);
}
/* Cuando la lista se desplaza sola (Inicio y Movimientos) la pantalla no se
   mueve y la cabecera se queda quieta; en el resto se desplaza la página
   entera, con la barra de pestañas fija encima.

   La única pantalla que nunca se desplaza es "Nuevo gasto" (.app-fixed): ahí el
   teclado tiene que quedarse abajo y el botón Guardar visible pase lo que pase. */
.app-lista .screen { overflow: hidden; }
.screen.no-tabbar { padding-bottom: calc(16px + var(--safe-bottom)); }

.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* --------------------------------------------------------------- cabecera */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: calc(14px + var(--safe-top)) var(--pad) 8px;
  flex-shrink: 0;
}
.topbar h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0;
  text-align: center;
  flex: 1;
}
/* Logo de la aplicación, a la derecha de la cabecera. Ocupa el hueco que antes
   dejaba .spacer-44, de modo que el título sigue quedando centrado entre el
   botón de volver y el logo. */
.topbar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
}
/* En Inicio va a la izquierda y con la misma caja que el botón de salir. */
.topbar-logo.boxed { width: 38px; height: 38px; border-radius: 10px; }

.topbar .greeting {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.iconbtn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: oklch(28% 0.02 250);
  cursor: pointer;
  border-radius: 12px;
  padding: 0;
}
.iconbtn.boxed { background: var(--neutral); width: 38px; height: 38px; min-width: 38px; border-radius: 10px; }
.iconbtn:active { background: var(--neutral); }
.iconbtn[disabled] { opacity: .35; }
.spacer-44 { width: 44px; min-width: 44px; }

/* ------------------------------------------------------- tarjeta de margen */

.statecard {
  margin: 0 var(--pad);
  padding: 20px;
  border-radius: var(--r-card);
  flex-shrink: 0;
  background: var(--sc-bg, var(--accent));
  color: var(--sc-text, #fff);
}
.statecard .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.statecard .label { font-size: 13px; color: var(--sc-muted, oklch(88% 0.04 190)); }
.statecard .amount {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  color: var(--sc-text, #fff);
  line-height: 1.1;
}
.statecard .amount.small { font-size: 24px; }
.statecard .caption {
  font-size: 13.5px;
  color: var(--sc-muted, oklch(88% 0.04 190));
  margin-top: 8px;
  line-height: 1.4;
}
/* Fondos (PiBank…) bajo el saldo: separados por una línea, más discretos. */
.statecard .fondos {
  margin-top: 12px; padding-top: 8px;
  border-top: 1px solid var(--sc-track, var(--accent-dark));
  display: flex; flex-direction: column; gap: 2px;
}
.statecard .fondos a {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  min-height: 32px; text-decoration: none; font-size: 13.5px;
  color: var(--sc-muted, oklch(88% 0.04 190));
}
.statecard .fondos .n { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.statecard .fondos .i {
  font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--sc-text, #fff); white-space: nowrap;
}
.statecard .navarrow {
  width: 32px; height: 32px; min-width: 32px;
  border: 0; background: transparent; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--sc-muted, oklch(88% 0.04 190));
  cursor: pointer;
}
.statecard .bar {
  height: 8px; border-radius: 4px; margin-top: 10px; overflow: hidden;
  background: var(--sc-track, var(--accent-dark));
}
.statecard .bar > i { display: block; height: 100%; background: var(--sc-fill, var(--accent-soft)); }
.statecard .foot {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; margin-top: 8px; color: var(--sc-muted, oklch(88% 0.04 190));
}
.statecard .detailbtn {
  display: inline-flex; align-items: center; gap: 4px;
  background: transparent; border: 0; padding: 4px 0; cursor: pointer;
  color: var(--sc-text, #fff); font-size: 13px; font-weight: 600;
}

/* Estados (mismos cortes y colores que el prototipo) */
.state-ok        { --sc-bg: oklch(52% 0.09 190); --sc-text: #fff;                --sc-muted: oklch(88% 0.04 190); --sc-track: oklch(42% 0.08 190); --sc-fill: oklch(85% 0.06 190); }
/* Aviso: amarillo, no naranja. El naranja se queda para lo que ya se ha ido
   de las manos, y así los tres estados se distinguen de un vistazo. */
.state-attention { --sc-bg: oklch(93% 0.13 105); --sc-text: oklch(34% 0.07 100); --sc-muted: oklch(46% 0.08 100); --sc-track: oklch(86% 0.09 105); --sc-fill: oklch(74% 0.16 100); }
.state-alert     { --sc-bg: oklch(88% 0.1 55);   --sc-text: oklch(32% 0.08 55);  --sc-muted: oklch(44% 0.08 55);  --sc-track: oklch(80% 0.07 55);  --sc-fill: oklch(55% 0.16 45); }
.state-exceeded  { --sc-bg: oklch(87% 0.1 25);   --sc-text: oklch(30% 0.1 25);   --sc-muted: oklch(42% 0.09 25);  --sc-track: oklch(80% 0.06 25);  --sc-fill: oklch(50% 0.18 25); }
.state-none      { --sc-bg: var(--neutral);      --sc-text: var(--text);         --sc-muted: var(--muted);        --sc-track: var(--border);       --sc-fill: var(--accent); }

/* Desglose del margen */
.breakdown {
  margin: 8px var(--pad) 0;
  padding: 14px 16px;
  border-radius: var(--r-card-s);
  background: var(--surface);
  border: 1px solid var(--border);
}
.breakdown .line, .card .line {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 0; font-size: 13.5px; border-bottom: 1px solid var(--border);
}
.breakdown .line:last-of-type, .card > .line:last-of-type { border-bottom: 0; }
.breakdown .line .val, .card .line .val { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
/* Una linea del desglose que se puede abrir para ver de que se compone. */
.line-desp { border-bottom: 1px solid var(--border); }
.line-desp:last-of-type { border-bottom: 0; }
.line-desp > summary {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 7px 16px 7px 0; font-size: 13.5px;
  list-style: none; cursor: pointer; position: relative;
}
.line-desp > summary::-webkit-details-marker { display: none; }
.line-desp > summary::after {
  content: ''; position: absolute; right: 2px; top: 50%; margin-top: -5px;
  width: 6px; height: 6px;
  border-right: 2px solid var(--muted-2); border-bottom: 2px solid var(--muted-2);
  transform: rotate(45deg); transition: transform .15s ease;
}
.line-desp[open] > summary::after { transform: rotate(-135deg); margin-top: -2px; }
.line-desp > summary .val { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.line-desp > summary .n {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  background: var(--neutral); color: var(--muted); font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.line-desp.gris > summary { background: var(--surface-2); }
.line-desp .line { border-bottom: 0; }

/* Fila del desfase: dos lineas que se tocan juntas y llevan a la categoria. */
.desvrow { display: block; color: inherit; text-decoration: none; }
.desvrow:active { background: var(--surface-2); }
.desvrow .line { border-bottom: 0; padding-bottom: 2px; }
.desvrow .line.sub { padding-top: 0; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.desvrow:last-of-type .line.sub { border-bottom: 0; }

/* Linea sombreada: la que resume algo distinto de lo que hay encima. */
.breakdown .line.gris, .card .line.gris { background: var(--surface-2); }
.breakdown .line.gris > span:first-child, .card .line.gris > span:first-child { padding-left: 4px; }
.breakdown .line.total, .card .line.total { border-top: 1px solid var(--border-strong); font-weight: 700; padding-top: 10px; margin-top: 4px; }
.card .line.sub { font-size: 12.5px; color: var(--muted); padding-left: 14px; }
.breakdown .note { font-size: 12px; color: var(--muted-2); margin-top: 10px; line-height: 1.5; }

/* Marca "real" vs "estimado" */
.tag-est, .tag-real, .tag-info {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 6px; vertical-align: middle;
  margin-left: 6px;
}
.tag-est  { background: oklch(93% 0.04 95); color: oklch(40% 0.08 80); }
.tag-real { background: oklch(93% 0.03 190); color: oklch(40% 0.07 190); }
.tag-info { background: oklch(92% 0.004 250); color: oklch(45% 0.015 250); }

/* Lo informativo es lo que se paga con dinero ya apartado en un fondo: no sale
   de la cuenta este mes, asi que se ve pero no se lee como un gasto mas. */
.informativo, .informativa {
  background: oklch(96.5% 0.003 250);
  font-style: italic;
}
.informativo .name, .informativo .amt, .informativa .nombre { font-style: italic; }
.dom-card.informativa { border-color: var(--border); }
.gasto-fila.informativo .amt { color: var(--muted-2); }

/* El recibo y su transferencia son la misma cosa contada dos veces: van pegados,
   la transferencia colgando del recibo, y los dos sobre gris muy claro para que
   se lean como un bloque y no como dos domiciliaciones distintas. */
.card.dom-card { margin: 0 0 10px; }
.card.dom-card.informativa, .card.dom-card.transferencia {
  background: oklch(96.5% 0.003 250);
  border-color: var(--border);
}
.card.dom-card.con-hijo {
  margin-bottom: 6px;
  border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;
}
.card.dom-card.transferencia {
  margin: 0 0 10px 20px;
  border-top-left-radius: 8px; border-top-right-radius: 8px;
  position: relative;
  font-style: normal;
}
/* El enganche: una linea que baja del recibo y gira hacia la tarjeta de abajo. */
.card.dom-card.transferencia::before {
  content: ''; position: absolute; left: -13px; top: -16px; bottom: 50%; width: 11px;
  border-left: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  border-bottom-left-radius: 9px;
}

/* ---------------------------------------------------------------- avisos */

.alertcard {
  margin: 12px var(--pad) 0;
  padding: 12px 14px;
  border-radius: var(--r-card-s);
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  display: flex; gap: 10px; align-items: flex-start;
  flex-shrink: 0;
  text-align: left;
  width: calc(100% - var(--pad) * 2);
  cursor: pointer;
}
.alertcard svg { flex-shrink: 0; margin-top: 1px; color: var(--warn-icon); }
/* Con cabecera propia la tarjeta se apila: primera línea el triángulo junto al
   rótulo, y debajo los cargos. El icono se centra con el texto del rótulo, no
   con el bloque entero. */
/* Las dos tarjetas de aviso son desplegables y comparten cabecera: mismo alto
   plegadas, mismo chevron, mismo globo con el numero. */
.alertcard.stack { display: block; padding: 3px 14px; cursor: default; }
/* Dentro de la tarjeta, un bloque plegable por origen del dinero: la cuenta y
   cada fondo. Plegados se ven solo los rotulos con su total. */
.alertcard details.bloque + details.bloque > summary {
  border-top: 1px solid var(--warn-border); margin-top: 2px; padding-top: 4px;
}
.alertcard > summary, .alertcard details.bloque > summary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  position: relative; padding-right: 18px;
  list-style: none; cursor: pointer;
  min-height: 26px;
  font-size: 13px; font-weight: 600; color: var(--warn-title);
}
.alertcard > summary::-webkit-details-marker,
.alertcard details.bloque > summary::-webkit-details-marker { display: none; }
.alertcard > summary::after, .alertcard details.bloque > summary::after {
  content: '';
  position: absolute; right: 2px; top: 50%; margin-top: -6px;
  width: 7px; height: 7px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s ease;
}
.alertcard[open] > summary::after,
.alertcard details.bloque[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.alertcard > summary .n, .alertcard details.bloque > summary .n {
  font-variant-numeric: tabular-nums; font-size: 11.5px; font-weight: 600;
  background: var(--warn-border); color: var(--warn-title);
  border-radius: 999px; padding: 1px 8px;
}
.alertcard.stack .cuerpo { padding: 2px 0 8px; }
.alertcard .t { font-size: 13px; font-weight: 600; color: var(--warn-title); }
.alertcard .s { font-size: 13px; color: var(--warn-text); }
/* Excesos de presupuesto: naranja pálido y de poca altura. Van aparte de los
   cargos por llegar porque son otra cosa: uno es dinero que va a salir, el otro
   un límite que te has pasado. */
/* Cargos por llegar: una línea por cargo — fecha, importe y nombre —, con las
   columnas alineadas para poder leerlas en vertical de un vistazo. */
.alertcard .cargo {
  display: flex; gap: 10px; align-items: baseline; color: inherit; text-decoration: none;
  font-size: 13px; line-height: 1.6; color: var(--warn-title);
}
/* Ya cobrado: no se quita de la lista, se tacha. El mes se lee entero —lo que
   ha caido y lo que falta— sin que la tarjeta se vacie sola. */
.alertcard .cargo.pagado { opacity: .45; }
.alertcard .cargo.pagado .i, .alertcard .cargo.pagado .n { text-decoration: line-through; }

/* Cobros de la otra cuenta: se ven, pero no son dinero que salga de aqui. */
.alertcard .cargo.externo { opacity: .62; font-style: italic; }

.alertcard .cargo .f { flex: 0 0 42px; color: var(--warn-text); font-variant-numeric: tabular-nums; }
.alertcard .cargo .i {
  flex: 0 0 78px; text-align: right; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.alertcard .cargo .n {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.alertcard.budget {
  background: oklch(93% 0.062 62);
  border-color: oklch(85% 0.09 62);
  padding: 3px 14px;
  margin-top: 8px;
  display: block;
  cursor: default;
}
/* Desplegable nativo: sin JavaScript y por tanto sin problemas con la CSP. */
/* Centrado como el de cargos: el chevron se saca del centro con position para
   que el rotulo quede en el eje de la tarjeta, no desplazado por la flecha. */
.alertcard.budget > summary { font-size: 12.5px; color: oklch(42% 0.09 55); }
.alertcard.budget > summary .n { background: oklch(85% 0.09 62); color: oklch(36% 0.11 55); }
.alertcard.budget .cuerpo { padding: 4px 0 6px; }
.alertcard.budget .mas {
  display: inline-block; margin-top: 8px; padding: 6px 0;
  font-size: 12.5px; font-weight: 600; color: oklch(42% 0.09 55);
}
.alertcard.budget .t {
  font-size: 12.5px; font-weight: 600; color: oklch(42% 0.09 55);
  line-height: 1.45;
}
.alertcard.budget .s { font-size: 12.5px; font-weight: 400; color: oklch(48% 0.06 55); }
.alertcard.budget .t + .t { margin-top: 3px; }

.alertcard.sev-info { border-color: var(--border-strong); background: var(--surface-2); }
.alertcard.sev-info svg { color: var(--muted); }
.alertcard.sev-info .t { color: var(--text); }
.alertcard.sev-info .s { color: var(--muted-2); }

/* --------------------------------------------------------------- secciones */

.sectionhead {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 18px var(--pad) 8px;
  flex-shrink: 0;
}
.sectionhead .title {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  line-height: 1.35;
}
/* En Inicio el rótulo comparte línea con "Ver todos" y no debe empujarlo. */
.sectionhead .title.one-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sectionhead .action {
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: none; border: 0; padding: 6px 0; cursor: pointer; white-space: nowrap;
}
/* Un total de gasto no es una accion: va en negro y con su signo. */
.sectionhead .action.gasto { color: var(--text-strong); font-variant-numeric: tabular-nums; cursor: default; }

/* Tarjeta que contiene una lista: las filas van al borde, con su separador, y
   la tarjeta solo pone el fondo y el redondeo. */
/* Tarjeta-lista: mismo ancho que la tarjeta de estado de arriba (las dos con
   el margen lateral de --pad) y con su propio rotulo dentro. */
.listcard { padding: 0 14px; margin: 0 var(--pad) 12px; }
.listcard .lc-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.listcard .lc-head .title {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.listcard .lc-head .action { font-size: 12.5px; font-weight: 600; color: var(--accent); white-space: nowrap; }
/* Un pastel por tarjeta: de un vistazo se distingue lo que has gastado tu de
   lo que pasa solo por el banco, sin tener que leer el rotulo. */
.listcard.tono-a { background: oklch(97% 0.022 195); border-color: oklch(90% 0.035 195); }
.listcard.tono-b { background: oklch(97% 0.025 300); border-color: oklch(90% 0.04 300); }
.listcard.tono-c { background: oklch(97% 0.022 145); border-color: oklch(90% 0.035 145); }
.listcard.tono-d { background: oklch(97% 0.03 70); border-color: oklch(90% 0.05 65); }
.listcard.tono-a .lc-head, .listcard.tono-a .mv { border-color: oklch(91% 0.028 195); }
.listcard.tono-b .lc-head, .listcard.tono-b .mv { border-color: oklch(91% 0.032 300); }
.listcard.tono-c .lc-head, .listcard.tono-c .mv { border-color: oklch(91% 0.028 145); }
.listcard.tono-d .lc-head, .listcard.tono-d .mv { border-color: oklch(91% 0.04 65); }

/* Bloques plegables de la pantalla de Gastos: el rotulo lleva su total y el
   chevron, y plegado no ocupa mas que una linea. */
.bloque-gastos > summary { list-style: none; cursor: pointer; position: relative; padding-right: 28px; }
.bloque-gastos > summary::-webkit-details-marker { display: none; }
.bloque-gastos > summary .tit { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bloque-gastos > summary .sub {
  font-size: 11px; font-weight: 500; color: var(--muted-2); letter-spacing: 0;
  text-transform: none; font-variant-numeric: tabular-nums;
}
.bloque-gastos > summary .tot {
  font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text); white-space: nowrap; margin-right: 10px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
}
.bloque-gastos > summary .tot .cap {
  font-size: 10.5px; font-weight: 600; color: var(--muted-2);
  text-transform: uppercase; letter-spacing: .04em;
}
.bloque-gastos > summary::after {
  content: '';
  position: absolute; right: 2px; top: 50%; margin-top: -7px;
  width: 7px; height: 7px;
  border-right: 2px solid var(--muted-2); border-bottom: 2px solid var(--muted-2);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s ease;
}
.bloque-gastos[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.bloque-gastos:not([open]) > summary { border-bottom: 0; margin-bottom: 0; padding-bottom: 12px; }
/* Filas mas juntas: en una lista larga se ven bastantes mas de un vistazo. */
.listcard .mv { min-height: 0; padding: 6px 0; }
.listcard .mv .name { font-size: 13px; line-height: 1.25; }
.listcard .mv .meta { font-size: 11px; line-height: 1.2; }
.listcard .mv:last-child { border-bottom: 0; }
/* Fila con barrita de color y fecha en columna: el color es el de la categoria,
   asi que la lista se puede leer por el margen sin llegar al texto. */
.mv.conbarra { gap: 8px; }
.mv.conbarra .barra {
  flex: 0 0 3px; align-self: stretch; min-height: 26px;
  border-radius: 2px; background: var(--border-strong);
}
.mv.conbarra .fecha {
  flex: 0 0 44px;
  font-size: 11.5px; color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.listcard .empty { padding: 14px 0; }

/* Buscador compacto: se sigue tecleando igual pero ocupa un tercio menos de
   alto. El tamano de letra se queda en 16px a proposito: por debajo, iOS hace
   zoom al enfocar el campo. */
input[type=search].compacto {
  min-height: 38px; padding: 7px 14px; line-height: 1.1; border-radius: 999px;
}

/* Fila de acciones en iconos: cuadraditos del mismo tamano, alineados a la
   derecha de la tarjeta. */
.btnrow.iconos { display: flex; gap: 8px; justify-content: flex-end; }
.btnrow.iconos form { display: contents; }
.btnrow.iconos .btn {
  flex: 0 0 40px; width: 40px; height: 34px; min-height: 34px;
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
/* Botón de sólo icono suelto (fuera de .btnrow), del alto de un campo. */
.btn.small.icono {
  width: 46px; min-width: 46px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}

/* El interruptor gasto/ingreso vive en la cabecera, en el sitio del titulo. */
.topbar .segmento { flex: 0 0 auto; margin: 0 auto; }

/* Gasto / Ingreso: dos pestanas pequeñas sobre el importe. */
.segmento {
  display: flex; gap: 4px;
  margin: 0; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; width: max-content; flex-shrink: 0;
}
.segmento button {
  border: 0; background: none; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 5px 18px; min-height: 30px; border-radius: 999px;
}
.segmento button.on { background: var(--surface); color: var(--text-strong); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.amountbox .val.income { color: var(--income); }

/* La cifra grande de Inicio: centrada y pulsable entera. */
.statecard .cifra {
  display: block; width: 100%; margin: 0; padding: 2px 0 0;
  background: none; border: 0; cursor: pointer; text-align: center;
  color: inherit; font: inherit; text-decoration: none;
}
.breakdown .line.sub {
  font-size: 12.5px; color: var(--muted);
  padding-left: 14px;
}
.breakdown .line.sub .cat-dot { margin-right: 6px; }

/* Boton de icono sin recuadro, para acompanar a un rotulo. */
.iconbtn.plain {
  background: none; border: 0; box-shadow: none;
  width: 32px; height: 32px; min-height: 32px; padding: 0;
}
.iconbtn.plain:active { background: var(--neutral); }

/* -------------------------------------------------------------- movimientos */

.list { display: flex; flex-direction: column; padding: 0 var(--pad); }
/* Hueco al final de la última lista para que el botón flotante no tape la
   última fila. El desplazamiento lo hace la pantalla entera, no la lista: así el
   gesto responde igual se ponga el dedo donde se ponga. */
.list.scroll { padding-bottom: 76px; }

.mv {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; cursor: pointer;
  min-height: 48px;
}
.mv:last-child { border-bottom: 0; }
.mv .info { min-width: 0; overflow: hidden; flex: 1; }
.mv .name, .mv .meta { display: block; }
.mv .name {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mv .meta {
  font-size: 11.5px; color: var(--muted-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mv .amt {
  font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  white-space: nowrap; flex-shrink: 0; color: var(--text);
}
.mv .amt.in { color: var(--income); }
.mv.paid .name, .mv.paid .amt { color: var(--muted-2); text-decoration: line-through; }
.mv .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.dot-review { background: oklch(65% 0.15 80); }
.dot-sync   { background: oklch(65% 0.1 250); }

/* ------------------------------------------------------------------ barras */

.progrow { display: flex; flex-direction: column; gap: 5px; }
.progrow .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; }
.progrow .top .n { font-weight: 600; color: var(--text); }
.cat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.progrow .top .v { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted-2); }
.progtrack { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.progtrack.thin { height: 6px; border-radius: 3px; }
.progtrack > i { display: block; height: 100%; background: var(--accent); }
.progtrack > i.over { background: var(--danger); }

/* Dos barras pegadas, sin hueco entre ellas: arriba lo gastado y abajo lo
   previsto. Pegadas y no separadas para que se comparen los extremos de un
   vistazo, que es lo unico que se mira aqui. */
.pareja { display: block; }
.pareja > i {
  display: block; height: 7px;
  background: var(--border);
}
.pareja > i.real { background: var(--accent); border-radius: 4px 4px 0 0; }
.pareja > i.real.over { background: var(--danger); }
.pareja > i.previsto { background: oklch(87% 0.055 185); border-radius: 0 0 4px 4px; }

/* Dos barras en la misma pista, una encima de otra: detras lo previsto (clara)
   y delante lo registrado (oscura). Solapadas, no apiladas: lo que se quiere
   ver es cuanto del plan llevas consumido. */
.doble {
  position: relative; height: 12px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); overflow: hidden;
}
.doble > i { position: absolute; left: 0; top: 0; display: block; border-radius: 6px; }
.doble > i.previsto { height: 100%; background: oklch(87% 0.055 185); }
.doble > i.real { height: 100%; background: var(--accent); }
.doble > i.real.over { background: var(--danger); }

/* --------------------------------------------------------------- barra tabs */

.tabbar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  height: var(--tabbar-h);
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: flex-start;
  padding: 8px var(--pad) var(--safe-bottom);
  z-index: 30;
}
@media (min-width: 900px) { .tabbar { max-width: 430px; } }
.tabbar .tabs { display: flex; flex: 1; justify-content: space-around; }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted-3); min-width: 56px; min-height: 44px; padding-top: 2px;
}
.tabbar a.on { color: var(--accent); }
.tabbar a.on span { font-weight: 600; }
.tabbar span { font-size: 10.5px; }

/* Fila de movimiento con acciones directas: el cuerpo lleva al detalle y a su
   derecha quedan modificar y eliminar, sin tener que entrar primero. */
.mv-acciones { display: flex; align-items: center; gap: 2px; }
.mv-acciones .mv-cuerpo {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: inherit; text-decoration: none;
}
.mv-acciones form { display: flex; margin: 0; }
.mv-acciones .iconbtn { width: 40px; min-width: 40px; height: 40px; }

.fab {
  position: fixed;
  /* El prototipo lo solapa 26 px con la barra de pestañas. Aquí queda POR
     ENCIMA de ella: solapado tapaba el icono de Opciones y su área táctil, y
     hacía que la barra de Inicio pareciera desalineada respecto al resto de
     pantallas. Es una desviación deliberada del mockup, por accesibilidad. */
  bottom: calc(var(--tabbar-h) + 14px);
  z-index: 31;
  width: 58px; height: 58px;
  border-radius: 18px;
  background: var(--accent);
  border: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px oklch(52% 0.09 190 / .35);
  cursor: pointer;
  color: #fff;
}
/* Cerca del pulgar, a la derecha, como en el prototipo */
.fab { left: 50%; transform: translateX(calc(240px - 58px - 20px)); }
@media (max-width: 480px) { .fab { left: auto; right: 20px; transform: none; } }
@media (min-width: 900px) { .fab { transform: translateX(calc(215px - 58px - 20px)); } }

/* --------------------------------------------------- tirar para actualizar */

/* Circulito de "tirar para actualizar". Va sobre la cabecera y baja con ella:
   el contenido entero se desplaza, asi que el gesto se ve, no solo se cree. */
.ptr {
  position: fixed;
  top: calc(var(--safe-top) - 34px); left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
}
.ptr .aro {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
}
.ptr.listo .aro { border-color: var(--accent); border-top-color: var(--accent); }
.ptr.girando .aro { animation: ptr-giro .7s linear infinite; }
@keyframes ptr-giro { to { transform: rotate(360deg); } }

/* ------------------------------------------------------- esperando al server

   Cortina con giro para las operaciones que tardan: subir una actualizacion,
   reparar vencimientos, una copia de seguridad. Aparece con retardo, para que
   lo instantaneo no de un parpadeo, y se va sola al cargar la pagina nueva. */
.cargando {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
}
.cargando .aro {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: ptr-giro .7s linear infinite;
}
.cargando .txt { font-size: 14px; font-weight: 600; color: var(--text); }
.cargando .sub { font-size: 12.5px; color: var(--muted); max-width: 260px; }

/* ------------------------------------------------------------------ modal */

.modal-fondo {
  position: fixed; inset: 0; z-index: 60;
  background: oklch(20% 0.02 250 / .45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  width: 100%; max-width: 340px;
  background: var(--surface);
  border-radius: var(--r-card);
  padding: 20px;
  box-shadow: 0 20px 50px oklch(20% 0.02 250 / .3);
}
.modal-texto {
  margin: 0 0 18px;
  font-size: 14.5px; line-height: 1.5; color: var(--text-strong);
}
.modal-botones { display: flex; gap: 10px; }
.modal-botones .btn { flex: 1; }
body.modal-abierto { overflow: hidden; }

/* Ficha de un traspaso: solo lectura, dos columnas por linea. */
.modal.ficha { text-align: left; }
.modal.ficha .ficha-t { font-size: 16px; font-weight: 700; margin: 0 0 10px; }
.modal.ficha .ficha-l {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  font-size: 13.5px; padding: 7px 0; border-bottom: 1px solid var(--border);
}
.modal.ficha .ficha-l:last-of-type { border-bottom: 0; }
.modal.ficha .ficha-l span { color: var(--muted); }
.modal.ficha .ficha-l strong { font-variant-numeric: tabular-nums; text-align: right; }
/* Los dos botones de la ficha son solo icono: cuadrados y centrados. */
.modal.ficha .modal-botones { margin-top: 12px; }
.modal.ficha .modal-botones .btn {
  display: flex; align-items: center; justify-content: center;
  padding: 0; min-height: 46px;
}

/* ------------------------------------------------------------------ toast */

/* Arriba, sobre la cabecera: tras guardar un gasto la vista vuelve a Inicio y
   el aviso con "Deshacer" tiene que verse sin bajar la mirada al teclado. */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-top) + 8px);
  width: min(432px, calc(100% - 48px));
  background: oklch(20% 0.02 220);
  color: #fff;
  border-radius: var(--r-btn);
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 60;
}
.toast .actions { display: flex; gap: 12px; align-items: center; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; padding: 6px 2px; font-size: 13px; }
.toast .undo { font-weight: 700; color: oklch(75% 0.1 190); }
.toast .close { opacity: .6; font-size: 15px; }
.toast.err { background: oklch(35% 0.12 25); }

/* ------------------------------------------------------------- nuevo gasto */

/* La pantalla de registro no scrollea entera: el bloque de "Guardar" y el
   teclado quedan SIEMPRE fijos abajo y sólo se desplaza el contenido de en
   medio. Así el botón nunca queda tapado, que es el requisito. */
.app-lista { height: 100dvh; max-height: 100dvh; overflow: hidden; }
.app-lista .screen { min-height: 0; }

.app-fixed { height: 100dvh; max-height: 100dvh; overflow: hidden; }
.app-fixed .screen { height: 100%; min-height: 0; overflow: hidden; padding-bottom: 0; }
.add-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.add-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.add-form .savewrap, .add-form .keypad, .add-form .amountbox { flex-shrink: 0; }

/* Fecha e importe en la MISMA linea: el chip de fecha a la izquierda y la cifra
   al lado. Antes iban en dos filas y esa altura hacia falta abajo. */
.amountbox {
  display: flex; flex-direction: row; align-items: center; justify-content: center;
  gap: 12px;
  padding: 2px var(--pad) 4px; flex-shrink: 0;
}
.amountbox .amt { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.amountbox .val {
  font-size: 46px; font-weight: 700; color: var(--text-strong);
  font-variant-numeric: tabular-nums; line-height: 1.05;
}
.amountbox .val.zero { color: oklch(58% 0.015 250); }

.amountbox .who, .datechip {
  font-size: 12.5px; color: var(--muted-2);
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; padding: 7px 12px; border-radius: 999px;
  min-height: 36px; display: inline-flex; align-items: center;
}
.amountbox .who:active, .datechip:active { background: var(--neutral); }

/* El input de fecha cubre el chip sin verse: al tocarlo salta el selector del
   sistema, que en el iPhone es la rueda a la que ya está acostumbrado todo el
   mundo. Nada de calendarios propios. */
.datechip { position: relative; overflow: hidden; }
.datechip input[type=date] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0; background: none;
  -webkit-appearance: none; appearance: none;
}

.picker {
  margin: 6px var(--pad) 0;
  padding: 10px;
  border-radius: var(--r-card-s);
  background: var(--surface-2);
  flex-shrink: 0;
}
.picker .head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
  background: none; border: 0; padding: 4px 0; cursor: default; min-height: 32px;
}
.picker .head.clickable { cursor: pointer; }
.picker .head .t {
  font-size: 12.5px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Siempre tres filas de cinco, ocupen los iconos que ocupen: la rejilla no
   cambia de alto al pasar de categorias a comercios ni al filtrar, asi que nada
   se mueve bajo el dedo. Si hay mas de quince, la rejilla se desplaza dentro. */
.grid5 {
  --gap: 8px;
  --tile: calc((min(100vw, 480px) - 2 * var(--pad) - 20px - 4 * var(--gap)) / 5);
  /* Las filas, más bajas que anchas: el icono no necesita el alto de la casilla
     y así las tres filas ocupan menos, que es lo que deja aire entre la tarjeta
     y la fila de guardar. */
  --fila: calc(var(--tile) * 0.78);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: var(--fila);
  gap: var(--gap);
  height: calc(3 * var(--fila) + 2 * var(--gap));
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  align-content: start;
}
.tile {
  width: 100%; height: 100%;
  border-radius: var(--r-tile);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 0; padding: 2px;
  background: var(--neutral);
  color: oklch(35% 0.015 250);
  min-height: 44px;
  overflow: hidden;
}
.tile.on { background: var(--accent); color: #fff; }
.tile .txt { font-size: 13px; font-weight: 700; }
.tile.small .txt { font-size: 9.5px; font-weight: 700; letter-spacing: -.02em; }
.picker .more {
  margin-top: 12px; background: none; border: 0; padding: 8px 0;
  font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer;
}

.fields { padding: 8px var(--pad); display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], input[type=time], input[type=month],
input[type=tel], input[type=url], input[type=datetime-local], input[type=week],
input:not([type]), select, textarea {
  padding: 12px 14px;
  border-radius: var(--r-input);
  border: 1px solid var(--border-strong);
  font-size: 16px; /* 16px evita el zoom automático de iOS al enfocar */
  line-height: 20px; /* misma caja para texto, selects y fechas */
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-height: 46px;
}
textarea { min-height: 84px; resize: vertical; }
select { appearance: none; background-image: none; }

/* Los inputs de fecha no se estiran solos en iOS: se fuerzan al ancho y alto
   del resto de campos para que la ficha no quede desalineada. */
input[type=date], input[type=month], input[type=time] {
  appearance: none; -webkit-appearance: none;
  box-sizing: border-box; min-width: 0; display: block;
  /* El editor interno de fecha es mas alto que una linea de texto: se fija la
     altura para que la fila quede alineada con el resto de campos. */
  height: 46px; line-height: 20px;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--neutral); color: var(--muted-2); opacity: 1;
}

/* Dos o tres campos en una misma línea dentro de un formulario. */
.fila { display: flex; gap: 10px; align-items: flex-end; }
.fila > .field { flex: 1 1 0; min-width: 0; }
.fila > .field.corto { flex: 0 0 86px; }

/* Casilla con su texto al lado, tamaño de toque cómodo. */
.chk { display: flex; align-items: center; gap: 10px; font-size: 13.5px; min-height: 44px; }
.chk input { width: 20px; height: 20px; min-height: 20px; flex: 0 0 20px; margin: 0; }
.chk.mini { font-size: 12.5px; min-height: 38px; }
.chk.mini input { width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; }
.canales { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; min-height: 46px; }
.canales .chk { min-height: 46px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dashrow { display: flex; gap: 10px; }
.dashbtn {
  flex: 1; padding: 12px 0; border-radius: var(--r-input);
  border: 1px dashed var(--border-strong); background: transparent;
  font-size: 13px; color: oklch(50% 0.015 250);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; min-height: 46px;
}

.savewrap { padding: 0 var(--pad) 10px; flex-shrink: 0; }
/* Fecha y Guardar en la misma fila: la fecha ocupa un cuarto y el boton el
   resto, que es la proporcion con la que se usa —se guarda mucho, se cambia la
   fecha poco— y libera una fila entera para las categorias. */
.savewrap.savefila { display: flex; gap: 10px; align-items: stretch; }
/* Fecha y destino: estrechos, con el mismo borde y radio que Guardar. */
.savewrap.savefila .datechip,
.savewrap.savefila .destchip {
  flex: 0 0 auto; min-width: 64px; justify-content: center; min-height: 50px;
  border-radius: var(--r-btn, 14px); padding: 0 12px;
}
.savewrap.savefila .btn { flex: 1; }
.destchip {
  font-size: 12.5px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  display: inline-flex; align-items: center; cursor: pointer; white-space: nowrap;
  max-width: 34%; overflow: hidden; text-overflow: ellipsis;
}
.destchip.fondo { background: oklch(95% 0.04 300); border-color: oklch(85% 0.06 300); color: oklch(38% 0.12 300); }
.destchip:active { background: var(--neutral); }
.btn {
  width: 100%; padding: 14px 0; border: 0; border-radius: var(--r-btn);
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; min-height: 50px;
}
.btn[disabled], .btn.off { background: oklch(80% 0.01 250); cursor: default; }
.btn.sec { background: var(--neutral); color: oklch(35% 0.015 250); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 11px 16px; font-size: 14px; min-height: 44px; width: auto; }
.btnrow { display: flex; gap: 10px; }
.btnrow .btn { flex: 1; }

/* Teclado numérico en pantalla (decisión de diseño: réplica del prototipo,
   así el importe siempre usa coma decimal y el botón Guardar nunca queda
   tapado por el teclado del sistema). */
.keypad {
  background: oklch(93% 0.006 250);
  padding: 12px 18px calc(14px + var(--safe-bottom));
  flex-shrink: 0;
}
.keypad .keys { gap: 8px; }
.keypad .keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  background: var(--surface); border: 0; border-radius: var(--r-input);
  padding: 13px 0; text-align: center; font-size: 20px; font-weight: 600;
  color: var(--text); cursor: pointer; min-height: 50px;
}
.keypad button:active { background: var(--neutral); }

/* ------------------------------------------------------- esperando al server

   Cortina con giro para las operaciones que tardan: subir una actualizacion,
   reparar vencimientos, una copia de seguridad. Aparece con retardo, para que
   lo instantaneo no de un parpadeo, y se va sola al cargar la pagina nueva. */

/* ------------------------------------------------------------------ modal */

.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 70; padding: 20px;
}
.modal {
  width: 100%; max-width: 320px; background: var(--surface);
  border-radius: 18px; padding: 20px;
  max-height: 84dvh; overflow-y: auto;
}
.modal.wide { max-width: 400px; }
.modal h2 { font-size: 15px; font-weight: 700; color: var(--text-strong); margin: 0 0 12px; }
.modal p { font-size: 14px; color: oklch(25% 0.02 250); line-height: 1.45; margin: 0 0 16px; }

/* --------------------------------------------------------------- opciones */

.rows { display: flex; flex-direction: column; padding: 8px var(--pad); }
.row-link {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  color: var(--text); min-height: 52px; text-align: left; width: 100%;
  background: none; border-left: 0; border-right: 0; border-top: 0; cursor: pointer;
}
.row-link .l { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row-link .l > span { min-width: 0; }
.row-link .n { font-size: 14.5px; font-weight: 500; display: block; }
.row-link .d { font-size: 12.5px; color: var(--muted-2); display: block; line-height: 1.35; }
.row-link .r { display: flex; align-items: center; gap: 8px; color: oklch(65% 0.015 250); flex-shrink: 0; }
.row-link .badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 700; padding: 2px 7px; min-width: 20px; text-align: center;
}
.row-link .badge.warn { background: oklch(60% 0.15 55); }

.card {
  margin: 0 var(--pad) 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card-s);
  padding: 14px 16px;
}
.card h3 { font-size: 13px; font-weight: 700; margin: 0 0 10px; color: var(--text-strong); }
.card p { font-size: 13px; color: var(--muted-2); line-height: 1.5; margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }

.chiprow { display: flex; gap: 8px; padding: 6px var(--pad) 10px; overflow-x: auto; flex-shrink: 0; }
.chiprow.compact { padding: 8px var(--pad) 6px; }
.chiprow.compact .chip { padding: 7px 12px; min-height: 34px; font-size: 12px; }
.chip {
  padding: 9px 14px; border-radius: var(--r-chip); font-size: 12.5px; font-weight: 600;
  background: var(--neutral); color: oklch(45% 0.015 250); border: 0; cursor: pointer;
  white-space: nowrap; min-height: 38px;
}
.chip.on { background: var(--accent); color: #fff; }

.empty {
  margin: 24px var(--pad); padding: 20px 16px; border-radius: var(--r-card-s);
  background: var(--neutral); font-size: 13px; color: oklch(45% 0.015 250);
  text-align: center; line-height: 1.5;
}
.hint {
  margin: 0 var(--pad) 16px; padding: 12px 14px; border-radius: var(--r-card-s);
  background: var(--neutral); font-size: 12.5px; color: oklch(45% 0.015 250); line-height: 1.5;
}
.hint.warn { background: oklch(95% 0.02 90); color: oklch(45% 0.05 90); }
.hint.err  { background: oklch(94% 0.03 25); color: oklch(40% 0.1 25); }

.flash {
  margin: 8px var(--pad); padding: 12px 14px; border-radius: var(--r-card-s);
  font-size: 13px; line-height: 1.45;
}
.flash.ok  { background: oklch(94% 0.04 165); color: oklch(35% 0.09 165); }
.flash.err { background: oklch(94% 0.03 25);  color: oklch(40% 0.1 25); }
.flash.info{ background: var(--neutral); color: oklch(38% 0.015 250); }

.pending-banner {
  display: flex; align-items: center; gap: 8px;
  margin: 8px var(--pad) 0; padding: 10px 12px;
  border-radius: var(--r-card-s); background: oklch(94% 0.03 250);
  font-size: 12.5px; color: oklch(38% 0.06 250);
}
.pending-banner[hidden] { display: none; }

/* ---------------------------------------------------------------- tablas */

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--border); }
.tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tblwrap { overflow-x: auto; padding: 0 var(--pad); }

/* --------------------------------------------------------------- utilidades */

.mtop  { margin-top: 12px; }
.mtop2 { margin-top: 20px; }
.pad   { padding: 0 var(--pad); }
.muted { color: var(--muted-2); }
.small { font-size: 12.5px; }
.grow  { flex: 1; }
.center{ text-align: center; }
.nowrap{ white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Impresión: informe legible sin barras ni botones. */
@media print {
  .tabbar, .fab, .toast, .iconbtn, .no-print { display: none !important; }
  body, .app { background: #fff; max-width: none; box-shadow: none; }
  .screen { padding-bottom: 0; }
  .card, .statecard { break-inside: avoid; border: 1px solid #ddd; color: #000; }
  .statecard { background: #fff !important; --sc-text: #000; --sc-muted: #444; }
  a { color: #000; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Miembro de la familia: el campo del nombre y los iconos, en una linea. El
   campo cede el ancho que haga falta para que quepan los tres botones. */
.acciones-miembro { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.acciones-miembro form { display: flex; gap: 8px; min-width: 0; }
.acciones-miembro form.nombre { flex: 1; min-width: 0; }
.acciones-miembro form.nombre input { flex: 1; min-width: 0; }
.acciones-miembro .btn.small.icono { width: 42px; min-width: 42px; flex: none; }

/* Invitación viva dentro de la tarjeta de otra familia. */
.invit-pend {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  margin-top: 8px; padding: 8px 10px;
  background: var(--surface-2, oklch(97% 0.005 250)); border-radius: 10px;
}
.invit-pend form { flex: none; }

/* Cifra de sólo lectura para quien no administra la familia. */
.linea-lectura {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13.5px; padding: 9px 0; border-bottom: 1px solid var(--border);
}
.linea-lectura span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.linea-lectura:last-of-type { border-bottom: 0; }

/* Importe y, debajo, el saldo teórico tras el movimiento: la misma línea y el
   mismo estilo que la categoría de la izquierda. */
.mv .cifras {
  display: flex; flex-direction: column; align-items: flex-end;
  flex-shrink: 0; min-width: 0;
}
.mv .cifras .saldo { font-variant-numeric: tabular-nums; }

/* Traspaso del mes a un fondo: la cifra que hay que mandar al banco, dentro del
   bloque del fondo y con su desglose a un toque. */
.alertcard details.traspaso-mes > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  list-style: none; cursor: pointer; min-height: 26px;
  font-size: 13px; font-weight: 600; color: var(--warn-title);
  padding: 2px 18px 2px 0; position: relative;
}
.alertcard details.traspaso-mes > summary::-webkit-details-marker { display: none; }
.alertcard details.traspaso-mes > summary::after {
  content: ''; position: absolute; right: 2px; top: 50%; margin-top: -6px;
  width: 7px; height: 7px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
}
.alertcard details.traspaso-mes[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.alertcard details.traspaso-mes > summary .n {
  font-variant-numeric: tabular-nums; font-size: 12.5px;
  background: var(--warn-border); border-radius: 999px; padding: 1px 8px;
}
.alertcard details.traspaso-mes {
  border-bottom: 1px dashed var(--warn-border); margin-bottom: 4px; padding-bottom: 4px;
}

/* Cabeceras de las tarjetas de cargos: el globo de lo pendiente y, al lado, el
   saldo con el que se cuenta —el de la cuenta o el del fondo—, en hueco para no
   confundirlo con lo que está por salir. */
.alertcard .n.saldo {
  background: var(--surface); border: 1px solid var(--warn-border);
  color: var(--warn-title); font-weight: 600;
}
.alertcard .n.saldo.corto { color: oklch(48% 0.16 25); border-color: oklch(70% 0.14 25); }

/* Cobro que NO es mensual: el recibo entero de un seguro, un impuesto o un
   trimestre. Es lo que descoloca la caja del mes, así que se lee en rojo. */
.alertcard .cargo.puntual .i, .alertcard .cargo.puntual .n { color: oklch(48% 0.18 25); font-weight: 700; }
.alertcard .cargo.puntual.pagado .i, .alertcard .cargo.puntual.pagado .n { color: oklch(55% 0.10 25); }

/* Extracto del fondo: corregir un apunte con lo que dice el banco. */
.corregir-apunte { margin: -4px 0 6px; }
.corregir-apunte > summary {
  font-size: 12.5px; color: var(--accent); cursor: pointer;
  min-height: 32px; display: inline-flex; align-items: center; list-style: none;
}
.corregir-apunte > summary::-webkit-details-marker { display: none; }

/* Punteo con el banco */
.punteado { color: var(--accent); font-weight: 700; font-size: .9em; }
.punteo-saldo { display: grid; gap: 4px; margin-top: 10px; font-size: 13.5px; }
.punteo-saldo > div { display: flex; justify-content: space-between; gap: 10px; }
.punteo-saldo > div strong { font-variant-numeric: tabular-nums; }
.punteo-saldo > .ok strong { color: var(--accent); }
.punteo-saldo > .mal strong { color: var(--danger); }
.punteo .pt-fila { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line, oklch(92% 0.01 250)); }
.punteo .pt-chk { display: flex; align-items: flex-start; padding-top: 2px; min-width: 28px; min-height: 28px; }
.punteo .pt-chk input { width: 20px; height: 20px; }
.punteo .pt-cuerpo { flex: 1; min-width: 0; display: grid; gap: 6px; }
.punteo .pt-banco, .punteo .pt-app { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; }
.punteo .pt-app { color: var(--muted, oklch(48% 0.015 250)); }
.punteo .f { flex: 0 0 40px; font-variant-numeric: tabular-nums; }
.punteo .n { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.punteo .i { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.punteo .pt-fecha { font-size: 12.5px; display: flex; gap: 6px; align-items: center; min-height: 32px; }
.punteo select, .punteo input[type=text] { min-height: 40px; font-size: 14px; }
.punteo .pt-crear { gap: 6px; flex-wrap: wrap; }
.punteo .pt-crear > * { flex: 1 1 120px; min-width: 0; }
.acciones-punteo { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.acciones-punteo .btn { width: 100%; margin: 0; }
.punteo .pt-regla { flex-basis: 100%; flex-wrap: wrap; }
.punteo .pt-clave { flex: 0 1 140px; min-height: 32px; font-size: 13px; padding: 4px 8px; }
