/* finanzas-mario v2 · bloque 04: Resumen, Ajustes, cuadre con CaixaBank y las ventanas de pregunta (Borrar, Cobré).
   Mismo lenguaje que Hoy: usa los tokens --v2-* y las piezas de hoy.css (.tarjeta2, .boton2, .duda, .chip, .barra,
   .boton-grupo, .gasto2). Va DESPUÉS de hoy.css. Claro y oscuro salen solos de los tokens.
   Regla de color (01): los mandos van en TINTA; el color es de los grupos y del rojo. */

/* ------------------------------------------------------------ marco de las vistas */

.vista2 {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 30rem; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.vista2-cab { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.vista2-cab h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; }
/* Resumen: la cifra manda; el título va a tamaño de sección, como «Te quedan, por grupo» en Hoy (critico-ux, 19 nov) */
.vista2-cab-sec h1 { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; }

/* Error general (arriba de todo): en v2, caja roja suave */
#pantalla-app .error-general {
  max-width: calc(30rem - 32px); margin: max(12px, env(safe-area-inset-top)) auto 0; width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 16px; background: var(--v2-alerta-fondo); color: var(--v2-alerta);
}

/* Botones v2 que faltaban: con borde (secundario) y enlace en tinta */
.boton2-sec { background: transparent; color: var(--v2-tinta); border: 1.5px solid var(--v2-borde); }
.boton2:active:not(:disabled) { transform: scale(.98); }
.enlace2 {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; border: 0; background: none;
  color: var(--v2-tinta); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* Tarjetas: título con su «?» */
.tarjeta2-cab { display: flex; align-items: center; gap: 10px; justify-self: stretch; }
/* Subtítulo dentro de una tarjeta: separa con aire, sin raya (critico-ux, 19 nov 2026) */
.tarjeta2-cab.sub { margin-top: 12px; }
.tarjeta2-cab h3 { font-size: 1rem; font-weight: 700; }
.form2 { justify-items: stretch; gap: 14px; }
.form2 > .boton2, .form2 > .enlace2 { justify-self: start; }

/* Mensajes: el estado se queda a la vista (no es ayuda) */
.v2 .ok { color: var(--v2-tinta); font-weight: 700; }
.v2 .ok:not(:empty)::before { content: "✓ "; }
.v2 .aviso-pendiente { color: var(--v2-alerta); font-weight: 700; }
.nota2 { font-size: .8125rem; color: var(--v2-suave); line-height: 1.35; }
.total2 { font-weight: 700; }

/* ------------------------------------------------------------ campos */

.fila2 { display: grid; gap: 6px; min-width: 0; }
.vista2 label:not(.boton2), .dialogo2 label { display: block; font-size: .9375rem; font-weight: 600; color: var(--v2-tinta); }
.vista2 input[type="text"], .vista2 input[type="date"], .dialogo2 input[type="date"] {
  display: block; width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--v2-borde); border-radius: 12px; /* borde 3:1 sobre la tarjeta, en claro y en oscuro */
  background: var(--v2-fondo); color: var(--v2-tinta);
  font-family: var(--v2-letra); font-size: 1.0625rem; font-weight: 600; font-variant-numeric: tabular-nums; text-align: left;
}
.vista2 input::-webkit-date-and-time-value, .dialogo2 input::-webkit-date-and-time-value { text-align: left; }
.vista2 input::placeholder { color: var(--v2-suave); opacity: 1; font-weight: 500; }
.vista2 input:focus-visible, .dialogo2 input:focus-visible { outline: 3px solid var(--v2-tinta); outline-offset: 0; border-color: var(--v2-tinta); }
.vista2 input[aria-invalid="true"] { border: 2px solid var(--v2-alerta); }
/* Casilla con «€» dentro, a la derecha */
.campo2 { position: relative; display: block; }
.campo2 input { padding-right: 2.25rem !important; }
.campo2 > span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--v2-suave); font-weight: 600; pointer-events: none; }

.ir-cantidades { margin: -8px 0 -4px -4px; }
#cantidades-titulo { scroll-margin-top: 1rem; }

/* ------------------------------------------------------------ RESUMEN */

.res-actual { display: grid; gap: 4px; }
.res-etq { font-size: 1rem; font-weight: 600; color: var(--v2-suave); }
.res-num { font-size: clamp(3.5rem, 18vw, 4.5rem); font-weight: 800; line-height: 1; letter-spacing: -0.045em; white-space: nowrap; }
.res-num .eur, .res-ant-total .eur { font-size: .5em; font-weight: 700; letter-spacing: 0; margin-left: .08em; }
/* A 24 px, la mitad deja un «€» de 12 px que se lee diminuto: .7em, como las cifras pequeñas de Hoy (.vgrupo-num) */
.res-ant-total .eur { font-size: .7em; }
.res-sub { font-size: .9375rem; color: var(--v2-suave); }

.res-lista { margin-top: 12px; padding: 2px 16px; border-radius: var(--v2-r-tarjeta); background: var(--v2-superficie); }
.res-lista:empty { display: none; }
/* Rejilla fija (columna del chip de 32 px, importe pegado a la derecha) para que las columnas del periodo anterior
   caigan bajo las de arriba aunque su chip sea más pequeño. */
.res-fila { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 2.75rem; align-items: center; gap: 6px 12px; padding: 12px 0; }
.res-fila + .res-fila { border-top: 1px solid var(--v2-linea); }
.res-fila .chip { width: 32px; height: 32px; border-radius: 10px; grid-row: span 2; }
.res-fila .chip svg { width: 18px; height: 18px; }
.res-nombre { font-weight: 600; overflow-wrap: anywhere; hyphens: manual; }
.res-importe { font-weight: 800; white-space: nowrap; text-align: right; }
.res-parte { text-align: right; font-size: .875rem; color: var(--v2-suave); }
.res-fila .barra { grid-column: 2 / -1; }

/* Periodo anterior: misma forma, más pequeño */
.res-aviso { display: inline-flex; align-items: center; gap: 10px; font-size: .9375rem; color: var(--v2-suave); }
.res-anterior { display: grid; gap: 2px; padding-top: 8px; }
.res-ant-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.res-anterior h2 { font-size: 1.125rem; font-weight: 700; }
.res-ant-total { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; }
.res-peq { margin-top: 8px; }
.res-peq .res-fila { padding: 8px 0; row-gap: 4px; font-size: .9375rem; }
.res-peq .chip { width: 26px; height: 26px; border-radius: 8px; justify-self: start; }
.res-peq .chip svg { width: 15px; height: 15px; }
.res-peq .barra { height: 4px; }

/* ------------------------------------------------------------ AJUSTES */

/* Dinero por grupo: chip + nombre + casilla; debajo, lo del mes pasado y «Poner X» */
.cantidades-reparto { font-weight: 800; }
.cantidades-reparto[data-estado="de-mas"] { color: var(--v2-alerta); }
#btn-todas-propuestas { justify-self: start; }
.lista-cantidades { display: grid; }
.cantidad2 { display: grid; grid-template-columns: auto minmax(0, 1fr) 7.5rem; align-items: center; gap: 2px 10px; padding: 10px 0; }
.cantidad2 + .cantidad2 { border-top: 1px solid var(--v2-linea); }
.cantidad2 .chip { width: 32px; height: 32px; border-radius: 10px; }
.cantidad2 .chip svg { width: 18px; height: 18px; }
.vista2 .cantidad2 label { font-size: 1rem; overflow-wrap: anywhere; hyphens: manual; }
.cantidad2 input { text-align: right !important; }
.cantidad-info, .cantidad-error { grid-column: 2 / -1; }
.cantidad-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 10px; font-size: .8125rem; color: var(--v2-suave); }
.cantidad-info .enlace2 { font-size: .875rem; margin-right: -4px; }
.cantidad-error { font-size: .875rem; }

/* «Otros» y fijos: filas como «Últimos gastos» de Hoy (.gasto2) */
.lista2 { display: grid; }
.lista2:empty { display: none; }
.otro2 { flex-wrap: wrap; }
/* «Cambiar» (Otros) y «Borrar» (fijos): el mismo enlace en tinta, con el texto pegado al borde derecho */
.lista2 .gasto2 > .enlace2 { flex: none; margin-right: -4px; }
.cambiar-grupo { flex-basis: 100%; padding-bottom: 6px; }
.fijo2 .gasto2-importe { overflow-wrap: anywhere; }

.form-fijo { display: grid; grid-template-columns: minmax(0, 1fr) 8rem; gap: 10px; padding-top: 14px; border-top: 1px solid var(--v2-linea); }
.form-fijo > .error, .form-fijo > .boton2 { grid-column: 1 / -1; }
.form-fijo > .boton2 { justify-self: start; }

.salir2 { padding-top: 4px; }

/* ------------------------------------------------------------ CUADRE CON CAIXABANK */

.cuadre-volver { margin: 0 0 -12px -4px; }

/* Elegir archivo: el label hace de botón; el input queda oculto a la vista pero enfocable y accesible */
.cuadre-carga { position: relative; justify-items: stretch; }
.cuadre-archivo {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.cuadre-elegir { display: inline-flex; align-items: center; justify-content: center; min-height: 50px; text-align: center; }
.cuadre-archivo:focus-visible + .cuadre-elegir { outline: 3px solid var(--v2-tinta); outline-offset: 2px; }

#cuadre-resultado { display: flex; flex-direction: column; gap: 12px; margin-top: -8px; }
.cuadre-resumen { padding-inline: 4px; font-size: .8125rem; color: var(--v2-suave); line-height: 1.35; text-wrap: pretty; }

/* Cajas plegables (Ya apuntados, Parecen tus fijos, Internos): discretas; lo que manda es «Sin apuntar» */
.cuadre-caja { padding: 0 16px; border-radius: var(--v2-r-tarjeta); background: var(--v2-superficie); }
.cuadre-caja[open] { padding-bottom: 14px; }
.cuadre-caja summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px;
  list-style: none; font-weight: 700; cursor: pointer;
}
.cuadre-caja summary::-webkit-details-marker { display: none; }
.cuadre-caja summary::after {
  content: ""; flex: none; width: .55em; height: .55em; margin-right: .25em;
  border-right: 2px solid var(--v2-tinta); border-bottom: 2px solid var(--v2-tinta);
  transform: translateY(-25%) rotate(45deg);
}
.cuadre-caja[open] summary::after { transform: translateY(25%) rotate(-135deg); }
/* «Por qué están aquí ?»: abre la ayuda en la hoja */
.porque2 {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin-top: -6px; padding: 0; border: 0; background: none;
  font: inherit; font-size: .875rem; font-weight: 600; color: var(--v2-suave); cursor: pointer;
}
.porque2 .duda { width: 20px; height: 20px; font-size: .6875rem; }
.porque2 .duda::after { content: none; }

/* Progreso: se queda arriba al bajar por la lista */
.cuadre-progreso {
  position: sticky; top: 0; z-index: 10; display: grid; gap: 6px;
  margin-inline: -8px; padding: max(8px, env(safe-area-inset-top)) 8px 10px;
  /* El fondo tapa 8 px de más a cada lado (lo que pasa por debajo al bajar); la raya, solo el ancho de las tarjetas */
  background: linear-gradient(var(--v2-linea), var(--v2-linea)) center bottom / calc(100% - 16px) 1px no-repeat, var(--v2-fondo);
  font-size: .9375rem; font-weight: 700;
}
.cuadre-progreso progress {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 6px;
  border: 0; border-radius: 3px; background: var(--v2-pista); overflow: hidden;
}
.cuadre-progreso progress::-webkit-progress-bar { background: var(--v2-pista); border-radius: 3px; }
.cuadre-progreso progress::-webkit-progress-value { background: var(--v2-tinta); border-radius: 3px; }
.cuadre-progreso progress::-moz-progress-bar { background: var(--v2-tinta); border-radius: 3px; }
/* Al saltar con el teclado, lo enfocado no queda bajo el progreso */
html:has(#vista-cuadre:not([hidden]) #cuadre-resultado:not([hidden])) { scroll-padding-top: 5rem; }

.cuadre-nuevos { justify-items: stretch; gap: 8px; }

/* Cada movimiento: concepto e importe arriba; fecha debajo; luego su nota, los grupos o su enlace */
.lista-cuadre { display: grid; }
.cuadre-fila { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; padding-block: 14px; }
.cuadre-fila:first-child { padding-top: 4px; }
.cuadre-fila:last-child { padding-bottom: 0; }
.cuadre-fila + .cuadre-fila { border-top: 1px solid var(--v2-linea); }
.cuadre-fila > * { grid-column: 1 / -1; }
.cuadre-fila > .cuadre-hecho, .cuadre-fila-apartada > .cuadre-porque { grid-column: 1; }
/* El enlace conserva su diana de 44 px sin ocupar ese alto en la maqueta */
.cuadre-fila > .enlace2 { grid-column: 2; margin-block: -10px; }
/* margin-inline -4px: el texto empieza en el borde del resto, no tras el relleno de la diana */
.cuadre-fila > .cuadre-interno { grid-column: 1 / -1; justify-self: start; font-size: .875rem; margin-block: 0 -8px; margin-inline: -4px 0; }
.cuadre-fila > .error { font-size: .875rem; }

.cuadre-mov { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "concepto importe" "fecha fecha"; align-items: baseline; gap: 0 12px; }
/* El concepto llega del banco en MAYÚSCULAS: se rebaja con tamaño y peso; una línea con «…» */
.cuadre-concepto {
  grid-area: concepto; min-width: 0; font-size: .875rem; font-weight: 600; letter-spacing: .03em; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cuadre-importe { grid-area: importe; font-size: 1.0625rem; font-weight: 800; white-space: nowrap; }
.cuadre-fecha { grid-area: fecha; font-size: .8125rem; color: var(--v2-suave); }
/* «· pendiente» (bloque 07): el banco aún no cerró el cargo. Texto suave junto a la fecha, sin borde: no es un botón. */
.cuadre-pendiente { font-weight: 700; color: var(--v2-suave); }

/* ------------------------------------------------------------ CAIXABANK CONECTADO (bloque 07) */

/* Cuadre: «✓ Conectado · leído hace X» con «Volver a leer» al lado, siempre en una fila (el botón no baja;
   si el ancho aprieta, es el texto el que parte en dos líneas a su izquierda) */
.cuadre-banco { display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 12px; }
.cuadre-banco-estado { flex: 1 1 auto; min-width: 0; font-size: .875rem; color: var(--v2-suave); text-wrap: balance; }
.cuadre-banco .boton2 { flex: none; white-space: nowrap; }
.cuadre-banco-estado b { color: var(--v2-tinta); font-weight: 700; }
.cuadre-banco-estado b::before { content: "✓ "; }
.cuadre-conectar { display: grid; gap: 8px; }
.cuadre-conectar .boton2, #btn-reconectar-banco { min-height: 50px; }
/* El archivo como enlace (el banco manda): a la izquierda, a tamaño de enlace */
/* (gana a «.vista2 label:not(.boton2)», que lo pondría en bloque y en 600) */
.cuadre-carga .cuadre-elegir.enlace2 {
  display: inline-flex; justify-self: start; min-height: 44px; margin-inline: -4px 0; font-size: .9375rem; font-weight: 700;
}
/* Con el banco conectado, el archivo es un plan C: peso y color callados */
.cuadre-carga:has(#cuadre-banco:not([hidden])) .cuadre-elegir.enlace2 { font-weight: 500; color: var(--v2-suave); }

/* Hoy: aviso del permiso, pequeño y bajo la franja; no compite con el número. Siempre UNA línea: «Renovar» no
   baja; si el texto no cabe, se corta con «…». Sin fondo de tarjeta (jueces, 20 nov 2026). */
.aviso-banco {
  display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: -8px; padding: 0 0 0 4px; border-radius: var(--v2-r-tarjeta);
  font-size: .875rem; font-weight: 600; color: var(--v2-suave);
}
#aviso-banco-texto { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aviso-banco .enlace2 { flex: none; font-size: .875rem; white-space: nowrap; }
/* Caducado: superficie neutra y el texto en rojo. El fondo rojo es solo de «Te pasaste». */
.aviso-banco[data-estado="caducado"] { padding: 0 8px 0 16px; background: var(--v2-superficie); color: var(--v2-alerta); }

/* Ajustes: estado del banco. Caducado: manda «Volver a conectar» (tinta); «Desconectar» detrás, en gris */
.ajustes-banco { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; font-size: .875rem; color: var(--v2-suave); }
.ajustes-banco .enlace2 { font-size: .875rem; white-space: nowrap; }
.ajustes-banco .ajustes-banco-quitar { color: var(--v2-suave); font-weight: 600; }

.cuadre-fila-anadida .cuadre-concepto, .cuadre-fila-anadida .cuadre-importe { color: var(--v2-suave); font-weight: 600; }
.cuadre-hecho { font-size: .9375rem; font-weight: 700; }
.cuadre-hecho::before { content: "✓ "; }
.cuadre-porque { font-size: .875rem; color: var(--v2-suave); text-wrap: pretty; }

/* ------------------------------------------------------------ los 9 grupos en tamaño compacto (cuadre y «Cambiar») */

/* Los mismos botones del «+» en pequeño: dibujito arriba y nombre debajo, para que el nombre tenga todo el ancho
   y no se parta a 375 px (director-visual, 19 nov 2026). El cuadre trae 60-100 movimientos. */
.botones-grupo.compacto { gap: 6px; margin-top: 8px; }
.compacto .boton-grupo {
  min-height: 54px; gap: 3px; padding: 5px 3px;
  border-radius: 12px; background: var(--v2-fondo);
  font-size: .75rem; overflow-wrap: normal; word-break: keep-all;
}
.compacto .boton-grupo .chip { width: 24px; height: 24px; border-radius: 7px; }
.compacto .boton-grupo .chip svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------ la hoja del «?» en modo ayuda (texto, sin filas) */

#hoja-cuenta[data-modo="ayuda"] .hoja-sub { margin: 8px 0 4px; font-size: 1rem; line-height: 1.5; color: var(--v2-tinta); text-wrap: pretty; }
.cuenta:empty { display: none; }

/* ------------------------------------------------------------ ventanas de pregunta (Borrar, Quitar, Cobré) */

dialog.dialogo2 {
  width: min(24rem, calc(100% - 32px)); padding: 20px; border: 0; border-radius: var(--v2-r-tarjeta);
  background: var(--v2-superficie); color: var(--v2-tinta);
}
dialog.dialogo2::backdrop { background: rgb(0 0 0 / .45); }
.dialogo2 form { display: grid; gap: 14px; }
.dialogo2-texto { font-size: 1.0625rem; font-weight: 700; line-height: 1.4; text-wrap: pretty; overflow-wrap: anywhere; }
.dialogo2-botones { display: flex; gap: 10px; margin-top: 4px; }
.dialogo2-botones .boton2 { flex: 1; min-height: 50px; }

/* ------------------------------------------------------------ movimiento */

@media (prefers-reduced-motion: no-preference) {
  dialog.dialogo2[open] { animation: v2-ventana .2s cubic-bezier(.2, 0, 0, 1); }
  .boton2 { transition: transform .15s cubic-bezier(.2, 0, 0, 1); }
  .cuadre-caja summary::after { transition: transform .15s cubic-bezier(.2, 0, 0, 1); }
  @keyframes v2-ventana { from { opacity: 0; transform: scale(.97); } }
}
