/* Peto: hucha doméstica. Claro por defecto, oscuro de verdad; el color solo dice
   si el dinero entra, sale o pide atención. */

@font-face { font-family: "Instrument Sans"; font-weight: 400; font-display: swap; src: url(fonts/is-400.woff2) format("woff2"); }
@font-face { font-family: "Instrument Sans"; font-weight: 500; font-display: swap; src: url(fonts/is-500.woff2) format("woff2"); }
@font-face { font-family: "Instrument Sans"; font-weight: 600; font-display: swap; src: url(fonts/is-600.woff2) format("woff2"); }

:root {
  --niebla: #eef1f0;   /* fondo */
  --papel: #f8faf9;    /* superficies que se tocan: campos, desplegables, el ritmo */
  --tinta: #1e2526;
  --suave: #5c6869;
  --linea: #d3dbd9;
  --ria: #1f5b66;      /* acento: navegación, saldo, gráfico */
  --gasto: #9e3a3a;
  --ingreso: #2e6e52;
  --aviso: #b7791f;
  --pista: #dfe5e3;    /* fondo de las barras */
  --sombra: 0 1px 0 rgb(30 37 38 / .04), 0 8px 24px -12px rgb(30 37 38 / .18);
  --radio: 10px;
  --ancho: 1040px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --niebla: #172022; --papel: #1e292b; --tinta: #e4eae8; --suave: #93a19f; --linea: #2e3b3d;
    --ria: #82b9c2; --gasto: #e3958f; --ingreso: #84c7a5; --aviso: #e2b15a; --pista: #263234;
    --sombra: 0 1px 0 rgb(0 0 0 / .2), 0 8px 24px -12px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--niebla); color: var(--tinta);
  font: 400 16px/1.5 "Instrument Sans", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.2; }
h2 { font-size: 1.0625rem; }
a { color: var(--ria); }
code { font-size: .9em; }
:focus-visible { outline: 2px solid var(--ria); outline-offset: 2px; border-radius: 4px; }

/* --- Controles ----------------------------------------------------------- */

button, select, input {
  font: inherit; color: inherit; min-height: 40px; padding: 8px 12px;
  background: var(--papel); border: 1px solid var(--linea); border-radius: 8px;
}
button { cursor: pointer; font-weight: 500; }
button:hover { border-color: var(--suave); }
button:disabled { opacity: .55; cursor: progress; }
button.principal { background: var(--ria); border-color: var(--ria); color: var(--papel); }
button.discreto { background: transparent; }
button.icono { width: 40px; padding: 0; font-size: 1.25rem; line-height: 1; background: transparent; border-color: transparent; }
button.icono:hover { background: var(--papel); border-color: var(--linea); }
input::placeholder { color: var(--suave); }
input[type="number"] { text-align: right; }

/* --- Cabecera ------------------------------------------------------------ */

.cabecera {
  max-width: var(--ancho); margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: center; gap: 8px 24px;
}
.marca { font-weight: 600; font-size: 1.375rem; letter-spacing: -.02em; color: var(--tinta); text-decoration: none; }
.pestanas { display: flex; gap: 4px; flex: 1; }
.pestanas a {
  padding: 8px 12px; border-radius: 8px; color: var(--suave); text-decoration: none; font-weight: 500;
}
.pestanas a:hover { color: var(--tinta); }
.pestanas a[aria-current] { color: var(--tinta); background: var(--papel); box-shadow: inset 0 0 0 1px var(--linea); }
.mes { display: flex; align-items: center; gap: 2px; }
.mes[hidden] { display: none; }
#mes { min-width: 9.5em; text-align: center; font-weight: 500; }

#estado { max-width: var(--ancho); margin: 0 auto; padding: 0 24px; color: var(--gasto); }
#estado.ok { color: var(--suave); }
#estado:empty { display: none; }

main {
  max-width: var(--ancho); margin: 0 auto; padding: 8px 24px 64px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px;
}

/* Secciones sin caja: las separa el aire y una línea fina bajo el título. */
.bloque > h2, .bloque > header { padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--linea); }
.bloque > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bloque > header h2 { padding: 0; border: 0; margin: 0; }
.dos { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 40px; align-items: start; }
.vacio, .nota { color: var(--suave); margin: 12px 0 0; }
.nota a { color: inherit; }
.error { color: var(--gasto); }
.cifra { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ingreso { color: var(--ingreso); }

/* --- Resumen: el ritmo del mes ------------------------------------------- */

.ritmo {
  background: var(--papel); border-radius: 14px; box-shadow: var(--sombra);
  padding: 28px 32px 24px; display: grid; gap: 20px;
}
.ritmo-cabeza { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 32px; }
.ritmo-mes { color: var(--suave); font-weight: 500; margin: 0 0 2px; }
.ritmo-gasto { font-size: clamp(2.75rem, 7vw, 4.5rem); font-weight: 600; letter-spacing: -.035em; line-height: 1; }
.ritmo-gasto small { font-size: 1.0625rem; font-weight: 500; letter-spacing: 0; color: var(--suave); margin-left: 10px; }
.ritmo-datos { display: flex; gap: 32px; margin: 0; }
.ritmo-datos div { display: grid; gap: 2px; }
.ritmo-datos dt { color: var(--suave); font-size: .875rem; }
.ritmo-datos dd { margin: 0; font-size: 1.25rem; font-weight: 600; letter-spacing: -.01em; }
.ritmo-datos .negativo { color: var(--gasto); }

.pista { position: relative; height: 14px; border-radius: 7px; background: var(--pista); }
.pista > i {
  position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--ria);
  transform-origin: left; animation: llenar .9s cubic-bezier(.2, .7, .2, 1) both;
}
.pista.adelantado > i { background: var(--aviso); }
.pista.pasado > i { background: var(--gasto); }
.pista > b {  /* dónde deberías ir hoy */
  position: absolute; top: -6px; bottom: -6px; width: 2px; margin-left: -1px;
  background: var(--tinta); border-radius: 1px;
}
.pista > b::after {
  content: attr(data-dia); position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  font-size: .75rem; color: var(--suave); white-space: nowrap;
}
.ritmo-pista { padding-top: 22px; }
.ritmo-texto { margin: 12px 0 0; color: var(--suave); }
.ritmo-texto strong { color: var(--tinta); font-weight: 600; }
@keyframes llenar { from { transform: scaleX(0); } }
@keyframes girar { to { transform: rotate(1turn); } }

.avisos { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.avisos li { display: flex; gap: 10px; align-items: baseline; }
.avisos li::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--aviso); transform: translateY(-1px); }
.avisos li.over::before { background: var(--gasto); }

/* --- Listas de filas (categorías, recibos, cuentas, reglas) -------------- */

.filas { list-style: none; margin: 0; padding: 0; }
.filas > li { padding: 12px 0; border-bottom: 1px solid var(--linea); }
.filas > li:last-child { border-bottom: 0; }

.cat { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; align-items: baseline; }
.cat-nombre { background: none; border: 0; padding: 0; min-height: 0; font-weight: 500; text-align: left; color: var(--tinta); }
.cat-nombre:hover { color: var(--ria); text-decoration: underline; text-underline-offset: 3px; }
.cat-meta { color: var(--suave); font-size: .875rem; margin-left: 8px; font-weight: 400; }
.cat .cifra { font-weight: 500; }
.barra { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--pista); overflow: hidden; }
.barra i { display: block; height: 100%; border-radius: inherit; background: var(--ria); opacity: .85; }
.barra.warn i { background: var(--aviso); opacity: 1; }
.barra.over i { background: var(--gasto); opacity: 1; }
.cat.suelta .barra i { background: var(--suave); opacity: .5; }

.recibo { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; }
.recibo span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.recibo small { color: var(--suave); font-size: .875rem; }
.recibo .cifra { font-weight: 500; text-align: right; }

/* --- Gráfico de saldo ---------------------------------------------------- */

.grafico { position: relative; height: 240px; margin-top: 12px; touch-action: pan-y; }
.grafico svg { display: block; width: 100%; height: 100%; overflow: visible; }
.grafico .rejilla line { stroke: var(--linea); }
.grafico .cero { stroke: var(--gasto); stroke-dasharray: 3 4; opacity: .7; }
.grafico text { fill: var(--suave); font-size: 12px; font-family: inherit; }
.grafico .area { fill: var(--ria); opacity: .08; }
.grafico .trazo { fill: none; stroke: var(--ria); stroke-width: 1.75; stroke-linejoin: round; }
.grafico .foco { stroke: var(--tinta); stroke-width: 1; opacity: .35; }
.grafico circle { fill: var(--papel); stroke: var(--ria); stroke-width: 2; }
.grafico .bocadillo {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--tinta); color: var(--niebla); border-radius: 6px; padding: 4px 8px;
  font-size: .8125rem; white-space: nowrap;
}
.grafico .bocadillo[hidden] { display: none; }

/* --- Movimientos --------------------------------------------------------- */

.filtros { display: flex; flex-wrap: wrap; gap: 8px; }
.filtros input { flex: 1 1 220px; }
.resumen-filtro { color: var(--suave); margin: 12px 0 0; }

.dia { margin-top: 24px; }
.dia > header {
  display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--linea); color: var(--suave); font-size: .875rem; font-weight: 500;
}
.dia > header h3 { font-size: inherit; font-weight: inherit; }
.dia > header h3::first-letter { text-transform: uppercase; }
.mov {
  display: grid; grid-template-columns: minmax(0, 1fr) 176px 112px; gap: 2px 16px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--linea);
}
.mov:last-child { border-bottom: 0; }
.mov-quien { min-width: 0; }
.mov-quien b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov-quien small { display: block; color: var(--suave); font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov select { min-height: 32px; padding: 4px 8px; font-size: .875rem; width: 100%; }
.mov select.sin { color: var(--suave); border-style: dashed; }
.mov .cifra { text-align: right; font-weight: 500; }
.mov .cifra.neutro { color: var(--suave); font-weight: 400; }

/* --- Recurrentes --------------------------------------------------------- */

.total-recibos { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 24px; }
.total-recibos strong { font-size: clamp(2rem, 5vw, 2.75rem); font-weight: 600; letter-spacing: -.03em; line-height: 1.1; }
.total-recibos span { color: var(--suave); }
.recurrente { display: grid; grid-template-columns: minmax(0, 1fr) 9em 7em; gap: 2px 16px; align-items: baseline; }
.recurrente b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recurrente small { grid-column: 1; color: var(--suave); font-size: .8125rem; }
.recurrente .proximo { color: var(--suave); font-size: .875rem; }
.recurrente .cifra { text-align: right; font-weight: 500; }

/* --- Ajustes ------------------------------------------------------------- */

.cuenta { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; align-items: baseline; }
.cuenta b { font-weight: 500; }
.cuenta small { color: var(--suave); font-size: .8125rem; }
.cuenta .cifra { font-weight: 600; text-align: right; }
.enlazar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.enlazar select { flex: 1 1 220px; }
.presupuesto { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 16px; align-items: center; }
.presupuesto small { color: var(--suave); font-size: .8125rem; display: block; }
.nueva { display: flex; gap: 8px; margin-top: 16px; }
.nueva input { flex: 1; min-width: 0; }
.regla { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.regla small { color: var(--suave); }

dialog {
  border: 0; border-radius: 14px; padding: 28px; width: min(360px, calc(100vw - 32px));
  background: var(--papel); color: var(--tinta); box-shadow: var(--sombra);
}
dialog::backdrop { background: rgb(23 32 34 / .45); }
dialog form { display: grid; gap: 12px; }
dialog label { color: var(--suave); font-size: .875rem; }
dialog.identificar label:not(.casilla) { display: grid; gap: 4px; }
dialog .casilla { display: flex; align-items: center; gap: 8px; color: var(--tinta); }
dialog .casilla input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--ria); }
dialog .acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
dialog h2 { margin: 0; }
dialog .nota { margin: 0; color: var(--suave); font-size: .875rem; overflow-wrap: anywhere; }
.mov-nombre {
  display: block; max-width: 100%; min-height: 0; padding: 0; border: 0; background: none; color: var(--tinta);
  font-weight: 500; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mov-nombre:hover { color: var(--ria); text-decoration: underline; text-underline-offset: 3px; }
.nota-propia { color: var(--ria); font-weight: 500; }

/* --- Detalle de categoría ------------------------------------------------ */

.volver { color: var(--suave); text-decoration: none; font-weight: 500; margin-bottom: -16px; justify-self: start; }
.volver:hover { color: var(--ria); }
.barras { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; height: 140px; margin-top: 24px; }
.barras button {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 6px;
  height: 100%; min-height: 0; padding: 0; border: 0; border-radius: 0; background: none; color: var(--suave);
}
.barras button i { display: block; min-height: 2px; border-radius: 3px 3px 1px 1px; background: var(--ria); opacity: .28; transition: opacity .15s; }
.barras button span { font-size: .75rem; font-weight: 400; line-height: 16px; text-align: center; }
.barras button:hover i { opacity: .55; }
.barras button.actual i { opacity: 1; }
.barras button.actual span { color: var(--tinta); font-weight: 600; }
.barras .tope { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed var(--aviso); pointer-events: none; }
.cifras-cat { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; margin: 12px 0 0; }
.cifras-cat div { display: grid; gap: 2px; }
.cifras-cat dt { color: var(--suave); font-size: .875rem; }
.cifras-cat dd { margin: 0; font-size: 1.125rem; font-weight: 600; }
.segmentos { display: inline-flex; border: 1px solid var(--linea); border-radius: 8px; padding: 2px; gap: 2px; }
.segmentos button { min-height: 30px; padding: 0 10px; border: 0; background: none; font-size: .875rem; color: var(--suave); }
.segmentos button[aria-pressed="true"] { background: var(--papel); color: var(--tinta); box-shadow: 0 0 0 1px var(--linea); }

/* --- Móvil: pestañas abajo, todo en una columna ------------------------- */

@media (max-width: 760px) {
  .cabecera { padding: 12px 8px 12px 16px; gap: 4px; }
  .marca { flex: 1; }
  #mes { min-width: 0; font-size: .9375rem; white-space: nowrap; }
  /* Solo el icono; el texto sigue ahí para lectores de pantalla. */
  #sincronizar { width: 40px; padding: 0; border-color: transparent; font-size: 0; }
  #sincronizar::before { content: "↻"; font-size: 1.25rem; }
  #sincronizar:disabled::before { display: inline-block; animation: girar 1s linear infinite; }
  .pestanas {
    position: fixed; z-index: 10; inset: auto 0 0 0; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--papel); border-top: 1px solid var(--linea);
  }
  .pestanas a { flex: 1; text-align: center; padding: 10px 4px; font-size: .875rem; }
  .pestanas a[aria-current] { box-shadow: none; background: var(--niebla); }
  #estado { padding: 0 16px; }
  main { padding: 4px 16px 112px; gap: 32px; }
  .barras { gap: 3px; height: 120px; }
  .barras button span { font-size: .6875rem; }
  .dos { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .ritmo { padding: 20px 20px 18px; border-radius: 12px; }
  .ritmo-datos { gap: 24px; }
  .grafico { height: 200px; }
  .mov { grid-template-columns: minmax(0, 1fr) auto; }
  .mov select { grid-column: 1; grid-row: 2; width: auto; justify-self: start; max-width: 100%; }
  .mov .cifra { grid-column: 2; grid-row: 1; }
  .recurrente { grid-template-columns: minmax(0, 1fr) auto; }
  .recurrente .proximo { grid-column: 1; grid-row: 3; }
  .recurrente .cifra { grid-column: 2; grid-row: 1; }
  .presupuesto { grid-template-columns: minmax(0, 1fr) 112px; }
}

@media (prefers-reduced-motion: reduce) {
  .pista > i, #sincronizar:disabled::before { animation: none; }
}
