:root {
  --fondo: #f3f5f4;
  --superficie: #ffffff;
  --campo: #f7f9f8;
  --texto: #17201d;
  --suave: #5f6b67;
  --filo: #dde3e0;
  --acento: #0f766e;
  --acento-texto: #ffffff;
  --ingreso: #15803d;
  --gasto: #c2410c;
  --peligro: #b91c1c;
  --sombra: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0e1412;
    --superficie: #17201d;
    --campo: #1d2825;
    --texto: #e8eeec;
    --suave: #9aa8a3;
    --filo: #2a3733;
    --acento: #2dd4bf;
    --acento-texto: #06231f;
    --ingreso: #4ade80;
    --gasto: #fb923c;
    --peligro: #f87171;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; color: var(--suave); }

button, .boton, input, select, textarea { font: inherit; color: inherit; }
button, .boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0.55rem 1rem;
  border: 1px solid var(--filo); border-radius: 10px;
  background: var(--superficie); cursor: pointer; text-decoration: none; text-align: center;
}
button:disabled { opacity: 0.6; }
.primario { background: var(--acento); border-color: var(--acento); color: var(--acento-texto); font-weight: 600; }
.peligro { color: var(--peligro); }
.ancho { width: 100%; }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 0.55rem 0.7rem;
  border: 1px solid var(--filo); border-radius: 10px; background: var(--campo);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acento); outline-offset: -1px; }
label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--suave); margin-bottom: 0.75rem; }
label > input, label > select, label > textarea { color: var(--texto); font-size: 1rem; }
.dos { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 0.75rem; }
.dos input[type=date] { min-width: 0; }

.txt-ingreso { color: var(--ingreso); }
.txt-gasto { color: var(--gasto); }
.nota { color: var(--suave); font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }
.error { color: var(--peligro); font-size: 0.9rem; min-height: 1.2em; margin: 0.25rem 0; }
.error:empty { min-height: 0; }
.vacio { text-align: center; color: var(--suave); padding: 2.5rem 1rem; }

/* Entrar */
.entrar { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.entrar form { width: min(360px, 100%); display: grid; gap: 0.25rem; text-align: center; }
.entrar img { margin: 0 auto 0.5rem; }
.entrar h1 { margin-bottom: 1rem; }
.entrar label { text-align: left; }

/* Barra superior y pestañas */
.barra {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) 16px 0.6rem;
  background: var(--fondo); border-bottom: 1px solid var(--filo);
}
.barra h1 { font-size: 1.25rem; }
.mes { display: flex; align-items: center; gap: 0.25rem; font-weight: 600; font-size: 0.95rem; }
.mes button { min-height: 38px; width: 38px; padding: 0; font-size: 1.3rem; border-radius: 50%; }
.mes span { min-width: 5.5em; text-align: center; white-space: nowrap; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(150px + env(safe-area-inset-bottom)); }

.pestanas {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--superficie); border-top: 1px solid var(--filo);
}
.pestanas button {
  flex-direction: column; gap: 0.1rem; min-height: 58px; padding: 0.3rem 0;
  border: 0; border-radius: 0; background: none; font-size: 0.7rem; color: var(--suave);
}
.pestanas button span { font-size: 1.2rem; line-height: 1; }
.pestanas button.activa { color: var(--acento); font-weight: 600; }

.flotante {
  position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 6;
  width: 58px; height: 58px; border-radius: 50%; padding: 0;
  font-size: 2rem; line-height: 1; background: var(--acento); border: 0; color: var(--acento-texto);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
}

/* Tarjetas y cifras */
.tarjeta {
  display: block; width: 100%; text-align: left;
  background: var(--superficie); border: 1px solid var(--filo); border-radius: 14px;
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--sombra);
}
.tarjeta.alerta { border-color: var(--gasto); font-size: 0.95rem; cursor: pointer; }
.cifras { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
.cifra {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
  background: var(--superficie); border: 1px solid var(--filo); border-radius: 14px;
  padding: 0.85rem 1rem; box-shadow: var(--sombra); min-width: 0; text-align: left;
}
.cifra.ancha { grid-column: 1 / -1; }
.cifra small { color: var(--suave); font-size: 0.8rem; }
.cifra strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cifra.ancha strong { font-size: 1.7rem; }
.cifra em { font-style: normal; font-size: 0.8rem; color: var(--suave); }
.cifra.enlace { cursor: pointer; }

.grafica { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.5rem; height: 140px; align-items: end; }
.columna { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 0.3rem; }
.pares { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.pares i { width: 40%; max-width: 18px; min-height: 2px; border-radius: 4px 4px 0 0; }
.columna small { font-size: 0.75rem; color: var(--suave); }
.columna small.actual { color: var(--texto); font-weight: 700; }
i.ingreso, .punto.ingreso { background: var(--ingreso); }
i.gasto, .punto.gasto { background: var(--gasto); }
.leyenda { display: flex; align-items: center; gap: 0.4rem; justify-content: center; font-size: 0.8rem; color: var(--suave); margin: 0.75rem 0 0; }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 0.5rem; }

.categoria { margin-bottom: 0.7rem; }
.categoria > div:first-child { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.92rem; margin-bottom: 0.25rem; }
.medidor { display: block; height: 8px; border-radius: 4px; background: var(--campo); overflow: hidden; }
.medidor i { display: block; height: 100%; border-radius: 4px; }

.fila { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.35rem 0; font-variant-numeric: tabular-nums; }
.fila.grande { font-size: 1.15rem; border-top: 1px solid var(--filo); margin-top: 0.4rem; padding-top: 0.6rem; }

/* Listas */
.chips { display: flex; gap: 0.5rem; overflow-x: auto; margin-bottom: 0.75rem; padding-bottom: 2px; }
.chip { min-height: 36px; padding: 0.3rem 0.85rem; border-radius: 999px; font-size: 0.88rem; white-space: nowrap; }
.chip.activa { background: var(--acento); border-color: var(--acento); color: var(--acento-texto); }
.dia { text-transform: capitalize; }
.lista { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--superficie); border: 1px solid var(--filo); border-radius: 14px; overflow: hidden; box-shadow: var(--sombra); }
.lista li + li { border-top: 1px solid var(--filo); }
.lista button {
  width: 100%; display: flex; align-items: center; gap: 0.75rem; justify-content: flex-start;
  border: 0; border-radius: 0; background: none; padding: 0.7rem 0.9rem; text-align: left;
}
.lista .texto { flex: 1; min-width: 0; display: grid; gap: 0.15rem; }
.lista .texto strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista .texto small { color: var(--suave); font-size: 0.8rem; }
.lista .texto .medidor { margin-top: 0.3rem; }
.lista .monto { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; display: grid; justify-items: end; }
.lista .monto small { font-weight: 400; font-size: 0.75rem; color: var(--suave); }
.lista.apagada, .lista button.apagada { opacity: 0.6; }
.icono {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; background: var(--campo);
}
.icono.ingreso { color: var(--ingreso); }
.icono.gasto { color: var(--gasto); }
.buscar { margin-bottom: 0.75rem; }

/* Diálogo */
dialog {
  width: min(560px, calc(100% - 16px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 16px; background: var(--superficie); color: var(--texto);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form { padding: 1.1rem 1rem 1rem; }
dialog h2 { font-size: 1.2rem; margin-bottom: 1rem; }
.botones { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.botones.columna { flex-direction: column; align-items: stretch; }
.botones .peligro:first-child:not(:only-child) { margin-right: auto; }

.segmento { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-bottom: 1rem; border: 1px solid var(--filo); border-radius: 10px; overflow: hidden; }
.segmento label { margin: 0; }
.segmento input { position: absolute; opacity: 0; pointer-events: none; }
.segmento span { display: block; text-align: center; padding: 0.65rem; font-size: 1rem; color: var(--texto); cursor: pointer; }
.segmento input:checked + span { background: var(--acento); color: var(--acento-texto); font-weight: 600; }
.segmento input:focus-visible + span { outline: 2px solid var(--acento); outline-offset: -3px; }

.casilla { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.casilla label { display: flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 0.95rem; color: var(--texto); }
.casilla input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; margin: 0; }
.casilla select { width: auto; min-height: 36px; padding: 0.2rem 0.5rem; }

.item { display: grid; grid-template-columns: 1fr 58px 110px 36px; gap: 0.4rem; margin-bottom: 0.4rem; align-items: center; }
.item.encabezado { font-size: 0.75rem; color: var(--suave); margin-bottom: 0.2rem; }
.item .cant { text-align: center; padding: 0.55rem 0.3rem; }
.quitar { min-height: 36px; width: 36px; padding: 0; border: 0; background: none; color: var(--suave); }
/* En el celular la descripción ocupa su propio renglón y debajo van cantidad y valor */
@media (max-width: 520px) {
  .item { grid-template-columns: 64px 1fr 36px; gap: 0.4rem; padding-bottom: 0.6rem; margin-bottom: 0.6rem; border-bottom: 1px dashed var(--filo); }
  .item [name=descripcion] { grid-column: 1 / -1; }
  .item.encabezado { display: none; }
}

.abonos { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.abonos li { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid var(--filo); font-size: 0.92rem; }
.abonos li span { flex: 1; min-width: 0; }
.abonos li .quitar { min-height: 30px; width: 30px; }

.logo-fila { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.logo-fila label { margin: 0; color: var(--texto); font-size: 1rem; }
.logo-vista { max-height: 56px; max-width: 140px; border-radius: 6px; background: #fff; padding: 2px; }

.aviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: calc(100% - 32px); padding: 0.7rem 1.1rem; border-radius: 10px;
  background: var(--texto); color: var(--fondo); font-size: 0.95rem; box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
}
.aviso.error { background: var(--peligro); color: #fff; }
.casilla-sola { display: flex; align-items: center; gap: 0.5rem; margin: 0.6rem 0 0.25rem; font-size: 0.88rem; color: var(--suave); }
.casilla-sola input { width: 20px; min-height: 20px; height: 20px; margin: 0; flex: none; }
