:root {
  color-scheme: light;
  --fondo: #f4f3ef;
  --superficie: #fcfcfb;
  --borde: #e2e0da;
  --texto: #1b1b1a;
  --texto-2: #52514e;
  --texto-3: #6f6e69;
  --primario: #1c5cab;
  --primario-hover: #184f95;
  --primario-suave: #e6effb;
  --peligro: #b42318;
  --exito-suave: #e7f6ee;
  --casa: #2a78d6;
  --p1: #eb6834;
  --p2: #1baf7a;
  --pista: #ecebe6;
  --sombra: 0 1px 2px rgb(0 0 0 / .05), 0 1px 8px rgb(0 0 0 / .04);
  --radio: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fondo: #121211;
    --superficie: #1a1a19;
    --borde: #33332f;
    --texto: #f5f5f2;
    --texto-2: #c3c2b7;
    --texto-3: #9f9e95;
    --primario: #3987e5;
    --primario-hover: #5598e7;
    --primario-suave: #1c2a3d;
    --peligro: #f97066;
    --exito-suave: #16291f;
    --casa: #3987e5;
    --p1: #d95926;
    --p2: #199e70;
    --pista: #2a2a27;
    --sombra: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fondo: #121211; --superficie: #1a1a19; --borde: #33332f; --texto: #f5f5f2; --texto-2: #c3c2b7;
  --texto-3: #9f9e95; --primario: #3987e5; --primario-hover: #5598e7; --primario-suave: #1c2a3d;
  --peligro: #f97066; --exito-suave: #16291f; --casa: #3987e5; --p1: #d95926; --p2: #199e70;
  --pista: #2a2a27; --sombra: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primario); }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font-size: .9em; }
.suave { color: var(--texto-2); }
.oculto { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* --------------------------------------------------- estructura */
.cabecera {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 16px; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--superficie); border-bottom: 1px solid var(--borde);
}
.marca { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--texto); text-decoration: none; }
.quien { margin-left: auto; color: var(--texto-2); font-size: .9rem; }
.nav-escritorio { display: none; }
.contenido { max-width: 760px; margin: 0 auto; padding: 1rem 16px 2rem; }

.nav-movil {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: var(--superficie); border-top: 1px solid var(--borde);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-movil a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .72rem; color: var(--texto-2); text-decoration: none; padding: 4px 0;
}
.nav-movil a span { font-size: 1.25rem; line-height: 1; }
.nav-movil a[aria-current] { color: var(--primario); font-weight: 600; }
.nav-movil .nav-mas span {
  display: grid; place-items: center; width: 52px; height: 52px; margin-top: -22px;
  border-radius: 50%; background: var(--primario); color: #fff; font-size: 2rem; font-weight: 300;
  box-shadow: 0 4px 14px rgb(28 92 171 / .35);
}

@media (min-width: 860px) {
  body { padding-bottom: 0; }
  .nav-movil { display: none; }
  .nav-escritorio { display: flex; align-items: center; gap: .25rem; margin-left: 1rem; }
  .nav-escritorio a:not(.boton) { padding: .4rem .7rem; border-radius: 8px; color: var(--texto-2); text-decoration: none; }
  .nav-escritorio a[aria-current] { background: var(--primario-suave); color: var(--primario); font-weight: 600; }
  .nav-escritorio .boton { margin-left: .5rem; }
}

/* --------------------------------------------------- tarjetas y datos */
.tarjeta {
  display: block; background: var(--superficie); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--sombra);
}
a.tarjeta { color: inherit; text-decoration: none; }
.heroe { text-align: center; }
.heroe p { margin: .15rem 0; }
.cifra-grande { font-size: 2.4rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.rejilla-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-bottom: 1rem; }
.rejilla-3 .tarjeta { margin: 0; }
.dato { display: flex; flex-direction: column; gap: .15rem; padding: .7rem .6rem; min-width: 0; }
.dato small { color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dato strong { font-size: clamp(.86rem, 3.9vw, 1.1rem); font-variant-numeric: tabular-nums; white-space: nowrap; }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.punto-casa { background: var(--casa); } .punto-p1 { background: var(--p1); } .punto-p2 { background: var(--p2); }

.selector-mes { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.selector-mes h1 { margin: .4rem 0 .8rem; text-align: center; }

.foto-factura {
  display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; padding: .9rem 1rem;
  border-radius: var(--radio); background: var(--primario); color: #fff; text-decoration: none;
}
.foto-factura > span:first-child { font-size: 1.8rem; }
.foto-factura small { display: block; opacity: .85; }

.balance-mini { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.en-paz { background: var(--exito-suave); }

.lista-pares { margin: 0; }
.lista-pares div { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--borde); }
.lista-pares div:last-child { border-bottom: 0; }
.lista-pares dt { color: var(--texto-2); }
.lista-pares dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.titulo-con-accion { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }

/* --------------------------------------------------- barras por categoría */
.barras-cat { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(6.5rem, 34%) 1fr auto; align-items: center; gap: .55rem .6rem; }
.barras-cat li { display: contents; }
.barra-etiqueta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.barra-pista { height: 10px; background: var(--pista); border-radius: 4px; overflow: hidden; }
.barra { display: block; height: 100%; width: 0; background: var(--casa); border-radius: 0 4px 4px 0; transition: width .4s; }
.barra-valor { font-variant-numeric: tabular-nums; font-size: .92rem; text-align: right; white-space: nowrap; }
.barra-valor small { color: var(--texto-3); margin-left: .25rem; }

/* --------------------------------------------------- lista de gastos */
.lista-gastos { list-style: none; margin: 0; padding: 0; }
.lista-gastos li + li { border-top: 1px solid var(--borde); }
.fila-gasto { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; color: inherit; text-decoration: none; }
.icono-cat { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--pista); font-size: 1.2rem; }
.fila-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fila-texto strong, .fila-texto small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-texto small { color: var(--texto-2); font-size: .82rem; }
.importe { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .2rem; }
.chip { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; border: 1px solid var(--borde); color: var(--texto-2); }
.chip-casa, .chip-p1, .chip-p2 { padding-left: .35rem; }
.chip-casa::before, .chip-p1::before, .chip-p2::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: .3rem; vertical-align: 1px;
}
.chip-casa::before { background: var(--casa); } .chip-p1::before { background: var(--p1); } .chip-p2::before { background: var(--p2); }
.vacio { color: var(--texto-2); text-align: center; padding: 1rem 0; }

/* --------------------------------------------------- formularios */
.formulario label, .filtros label { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; font-weight: 550; font-size: .95rem; }
.formulario small { font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--texto); background: var(--superficie);
  border: 1px solid var(--borde); border-radius: 10px; padding: .65rem .75rem; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primario); outline-offset: 1px; border-color: transparent; }
.input-importe { font-size: 1.4rem; font-weight: 650; }
fieldset { border: 0; padding: 0; margin: 0 0 .8rem; }
legend { font-weight: 550; margin-bottom: .4rem; font-size: .95rem; padding: 0; }
.formulario fieldset:not(.segmentado) { border: 1px solid var(--borde); border-radius: 12px; padding: .75rem; margin-bottom: 1rem; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.fila-accion { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.fila-accion label { flex: 1; min-width: 10rem; }
.fila-accion label.estrecho { flex: 0 0 5rem; min-width: 0; }
.fila-accion .boton { margin-bottom: .8rem; }

.segmentado { display: flex; flex-wrap: wrap; gap: .4rem; }
.segmentado legend { width: 100%; }
.segmentado label { margin: 0; flex: 1 1 auto; font-weight: 500; }
.segmentado input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmentado span {
  display: block; text-align: center; padding: .6rem .8rem; border: 1px solid var(--borde);
  border-radius: 10px; cursor: pointer; min-height: 44px; white-space: nowrap;
}
.segmentado input:checked + span { background: var(--primario); border-color: var(--primario); color: #fff; font-weight: 600; }
.segmentado input:focus-visible + span { outline: 2px solid var(--primario); outline-offset: 2px; }
.reparto summary { cursor: pointer; color: var(--texto-2); font-size: .9rem; padding: .3rem 0; }
.reparto label { margin-top: .6rem; }
.casilla { flex-direction: row !important; align-items: center; gap: .5rem !important; font-weight: 400 !important; }
.casilla input { width: auto; min-height: 0; }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--borde); background: var(--superficie); color: var(--texto);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.boton:hover { border-color: var(--texto-3); }
.boton-primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.boton-primario:hover { background: var(--primario-hover); border-color: var(--primario-hover); }
.boton-texto { background: none; border-color: transparent; color: var(--primario); font-weight: 500; }
.boton-peligro { color: var(--peligro); background: none; }
.boton-icono { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0; font-size: 1.5rem; border: 0; background: none; color: var(--texto); cursor: pointer; text-decoration: none; }
.ancho { width: 100%; }
.acciones { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.borrar { text-align: center; }

.zona-foto .botones-foto { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.zona-foto .boton { white-space: normal; text-align: center; padding: .55rem .5rem; line-height: 1.2; }
.miniatura { display: block; max-width: 100%; max-height: 320px; margin: .8rem auto 0; border-radius: 10px; border: 1px solid var(--borde); }
.factura-actual { margin: 0 0 .8rem; }
.ocr-estado { margin-top: .8rem; padding: .7rem .8rem; border-radius: 10px; background: var(--primario-suave); font-size: .92rem; }
.ocr-estado.ok { background: var(--exito-suave); }
.ocr-estado ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.cargando::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: .5rem; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .8s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }
.autorrellenado { background: var(--exito-suave); transition: background 1.5s; }
pre { white-space: pre-wrap; font-size: .8rem; max-height: 260px; overflow: auto; background: var(--pista); padding: .6rem; border-radius: 8px; }

.aviso { background: var(--exito-suave); border: 1px solid var(--borde); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.error { background: color-mix(in srgb, var(--peligro) 12%, var(--superficie)); color: var(--peligro); padding: .7rem 1rem; border-radius: 10px; }
.acceso { max-width: 420px; margin: 2rem auto; text-align: center; }
.acceso .formulario { text-align: left; margin-top: 1rem; }

.filtros { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 .75rem; }
.filtros .buscar, .filtros .acciones-filtro { grid-column: 1 / -1; }
.acciones-filtro { display: flex; gap: .5rem; }
@media (min-width: 700px) { .filtros { grid-template-columns: repeat(4, 1fr); } }

.lista-simple { list-style: none; margin: 0 0 1rem; padding: 0; }
.lista-simple li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .35rem 0; border-bottom: 1px solid var(--borde); }
.lista-simple li.apagada { opacity: .5; }
.lista-simple form { margin: 0; }
.derecha { display: flex; align-items: center; gap: .25rem; white-space: nowrap; }
.explicacion { padding-left: 1.2rem; margin: 0 0 1rem; color: var(--texto-2); }
.explicacion li { margin-bottom: .3rem; }

/* --------------------------------------------------- informes */
.botones-exportar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: .8rem; }
.exportar-mes { display: flex; gap: .6rem; align-items: flex-end; }
.exportar-mes label { display: flex; flex-direction: column; gap: .3rem; flex: 1; font-weight: 550; font-size: .95rem; }
.pestanas { display: flex; gap: .4rem; overflow-x: auto; margin-bottom: 1rem; }
.pestanas a { padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--borde); color: var(--texto-2); text-decoration: none; white-space: nowrap; background: var(--superficie); }
.pestanas a[aria-current] { background: var(--primario); border-color: var(--primario); color: #fff; font-weight: 600; }

.leyenda { display: flex; gap: 1rem; list-style: none; padding: 0; margin: 0 0 .8rem; font-size: .88rem; color: var(--texto-2); }
.leyenda li { display: flex; align-items: center; gap: .35rem; }
.grafico-meses {
  display: flex; align-items: stretch; gap: 4px; height: 220px; overflow-x: auto;
  border-bottom: 1px solid var(--borde); padding-top: 4px;
}
.col-mes { flex: 1 0 26px; max-width: 72px; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; cursor: default; outline: none; }
.col-mes:hover .pila, .col-mes:focus .pila { filter: brightness(1.08); }
.col-mes:focus-visible { outline: 2px solid var(--primario); outline-offset: 2px; border-radius: 4px; }
.pila { display: flex; flex-direction: column; gap: 2px; height: 0; border-radius: 4px 4px 0 0; overflow: hidden; }
.seg { display: block; min-height: 2px; }
.seg-casa { background: var(--casa); } .seg-p1 { background: var(--p1); } .seg-p2 { background: var(--p2); }
.etq-mes { text-align: center; font-size: .7rem; color: var(--texto-3); padding-top: .25rem; line-height: 1.15; min-height: 2.1em; }
.tooltip {
  position: fixed; z-index: 30; pointer-events: none; background: var(--texto); color: var(--superficie);
  padding: .5rem .65rem; border-radius: 8px; font-size: .82rem; line-height: 1.4; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
  font-variant-numeric: tabular-nums;
}
.tooltip strong { display: block; }

.tabla-scroll { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
.tabla { border-collapse: collapse; width: 100%; font-size: .88rem; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { padding: .5rem .55rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--borde); }
.tabla th:first-child { text-align: left; }
.tabla thead th { color: var(--texto-2); font-weight: 600; font-size: .8rem; }
.tabla tbody th { font-weight: 500; }
.tabla a { text-decoration: none; }
.etiqueta-opcional { display: flex; gap: .35rem; align-items: baseline; }
.etiqueta-opcional .suave { font-weight: 400; }
